lib/em-jack/connection.rb in em-jack-0.1.0 vs lib/em-jack/connection.rb in em-jack-0.1.1
- old
+ new
@@ -41,10 +41,29 @@
use(@tube)
watch(@tube)
end
end
+ def fiber!
+ eigen = (class << self
+ self
+ end)
+ eigen.instance_eval do
+ %w(use reserve ignore watch peek stats list delete touch bury kick pause release put).each do |meth|
+ alias_method :"a#{meth}", meth.to_sym
+ define_method(meth.to_sym) do |*args|
+ fib = Fiber.current
+ ameth = :"a#{meth}"
+ p [ameth, *args]
+ proc = lambda { |*result| fib.resume(*result) }
+ send(ameth, *args, &proc)
+ Fiber.yield
+ end
+ end
+ end
+ end
+
def use(tube, &blk)
return if @used_tube == tube
callback {
@used_tube = tube
@@ -193,10 +212,12 @@
def each_job(timeout = nil, &blk)
work = Proc.new do
r = reserve(timeout)
r.callback do |job|
blk.call(job)
-
+ EM.next_tick { work.call }
+ end
+ r.errback do
EM.next_tick { work.call }
end
end
work.call
end