examples/echo_worker.rb in pigato-0.2.27 vs examples/echo_worker.rb in pigato-0.3.0

- old
+ new

@@ -2,11 +2,26 @@ require "rubygems" require "#{File.dirname(__FILE__)}/../lib/pigato.rb" #require "pigato" -worker = Pigato::Worker.new('tcp://localhost:55555', 'echo') +ts = [] -loop do - request = worker.recv - worker.reply request +[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 + + loop do + request = worker.recv + if !request.nil? + worker.reply request + else + sleep 0.1 + end + end + } +end + +ts.each do |to| + to.join end