examples/worker_reverse_string.rb in gearman-ruby-3.0.1 vs examples/worker_reverse_string.rb in gearman-ruby-3.0.2

- old
+ new

@@ -1,27 +1,20 @@ require 'rubygems' require '../lib/gearman' # String reverse worker -servers = ['localhost:4730'] +servers = ['localhost:4731'] -t = nil jobnum = 0 -(0..1).each do - t = Thread.new { - w = Gearman::Worker.new(servers) - w.add_ability('reverse_string') do |data,job| - result = data.reverse - puts "Job: #{job.inspect} Data: #{data.inspect} Reverse: #{result} " - puts "Completed job ##{jobnum}" - jobnum += 1 - result - end - loop { w.work } - } +w = Gearman::Worker.new(servers) +w.add_ability('reverse_string') do |data,job| + result = data.reverse + puts "Job: #{job.inspect} Data: #{data.inspect} Reverse: #{result} " + puts "Completed job ##{jobnum}" + jobnum += 1 + result end +loop { w.work } -puts "Waiting for threads..." -t.join