examples/echo_worker.rb in pigato-0.3.1 vs examples/echo_worker.rb in pigato-0.4.0
- old
+ new
@@ -2,26 +2,36 @@
require "rubygems"
require "#{File.dirname(__FILE__)}/../lib/pigato.rb"
#require "pigato"
-ts = []
+def start
+ ts = []
-[0, 1, 2, 3, 4, 5, 6].each do |tid|
- ts << Thread.new {
- worker = Pigato::Worker.new('tcp://127.0.0.1:55555', 'echo')
- worker.start
+ (0..5).each do |tid|
+ ts << Thread.new {
+ worker = Pigato::Worker.new('tcp://127.0.0.1:55555', 'echo')
+ worker.start
- loop do
- request = worker.recv
- if !request.nil?
- worker.reply request
- else
- sleep 0.1
+ loop do
+ request = worker.recv
+ if !request.nil?
+ worker.reply request
+ else
+ sleep 0.1
+ end
end
- end
- }
+ }
+ end
+
+ ts.each do |to|
+ to.join
+ end
end
-ts.each do |to|
- to.join
+(0..1).each do |pid|
+ fork do
+ start
+ end
end
+
+Process.waitall