Class: Temporal::Workflow::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/temporal/workflow/dispatcher.rb

Constant Summary collapse

WILDCARD =
'*'.freeze

Instance Method Summary collapse

Constructor Details

#initializeDispatcher

Returns a new instance of Dispatcher.



6
7
8
# File 'lib/temporal/workflow/dispatcher.rb', line 6

def initialize
  @handlers = Hash.new { |hash, key| hash[key] = [] }
end

Instance Method Details

#dispatch(target, event_name, args = nil) ⇒ Object



14
15
16
17
18
# File 'lib/temporal/workflow/dispatcher.rb', line 14

def dispatch(target, event_name, args = nil)
  handlers_for(target, event_name).each do |handler|
    handler.call(*args)
  end
end

#register_handler(target, event_name, &handler) ⇒ Object



10
11
12
# File 'lib/temporal/workflow/dispatcher.rb', line 10

def register_handler(target, event_name, &handler)
  handlers[target] << [event_name, handler]
end