lib/gb_dispatch/manager.rb in gb_dispatch-0.0.3 vs lib/gb_dispatch/manager.rb in gb_dispatch-0.0.4

- old
+ new

@@ -12,16 +12,16 @@ # # If queue doesn't exists it will create you a new one. # Remember that for each allocated queue, there is new thread allocated. # @param name [String, Symbol] if not passed, default queue will be returned. # @return [GBDispatch::Queue] - def get_queue(name=:default) + def get_queue(name=:default_queue) name = name.to_sym queue = Celluloid::Actor[name] unless queue - supervisor = Queue.supervise_as name, name, @pool - queue = supervisor.actors.first + Queue.supervise as: name, args: [name, @pool] + queue = Celluloid::Actor[name] end queue end # Run asynchronously given block of code on given queue. @@ -34,10 +34,11 @@ # GBDispatch::Manager.instance.run_async_on_queue my_queue do # #my delayed code here - probably slow one :) # puts 'Delayed Hello World!' # end def run_async_on_queue(queue) + raise ArgumentError.new 'Queue must be GBDispatch::Queue' unless queue.is_a? GBDispatch::Queue queue.async.perform ->() { yield } end # Run given block of code on given queue and wait for result. # @@ -50,10 +51,11 @@ # puts 'Delayed Hello World!' # # return value # 42 # end def run_sync_on_queue(queue) + raise ArgumentError.new 'Queue must be GBDispatch::Queue' unless queue.is_a? GBDispatch::Queue future = queue.future.perform ->() { yield } future.value end # Run given block of code on given queue with delay. @@ -65,9 +67,10 @@ # my_result = GBDispatch::Manager.instance.run_after_on_queue 5, my_queue do # puts 'Hello World!' # end # def run_after_on_queue(time, queue) + raise ArgumentError.new 'Queue must be GBDispatch::Queue' unless queue.is_a? GBDispatch::Queue queue.perform_after time, ->(){ yield } end # :nodoc: