lib/tobox/worker.rb in tobox-0.5.1 vs lib/tobox/worker.rb in tobox-0.5.2

- old
+ new

@@ -31,17 +31,18 @@ private def do_work return if @finished - sum_fetched_events = @fetcher.fetch_events do |event| - event_type = event[:type].to_sym - args = message_to_arguments(event) - - if @handlers.key?(event_type) - @handlers[event_type].each do |handler| - handler.call(args) + sum_fetched_events = @fetcher.fetch_events do |events| + cs = @handlers.each_with_object({}) do |(callback, event_types), bucket| + events.each do |event| + (bucket[callback] ||= []) << message_to_arguments(event) if event_types.include?(event[:type].to_sym) end + end + + cs.each do |callback, evs| + callback.call(*evs) end end return if @finished