Class: Synapse::Command::CommandBus Abstract
- Inherits:
-
Object
- Object
- Synapse::Command::CommandBus
- Defined in:
- lib/synapse/command/command_bus.rb
Overview
Represents a mechanism for dispatching commands to their appropriate handlers
Command handlers can subscribe and unsubscribe to different command types. Only a single handler can be subscribed for a command type at one time.
Implementations can choose to dispatch commands in the calling thread or in another thread.
Direct Known Subclasses
Instance Method Summary collapse
-
#dispatch(command) ⇒ undefined
abstract
Dispatches the given command to the handler subscribed to its type.
-
#dispatch_with_callback(command, callback) ⇒ undefined
abstract
Dispatches the given command to the handler subscribed to its type and notifies the given callback of the outcome of the dispatch.
-
#subscribe(command_type, handler) ⇒ undefined
Subscribes the given handler to the given command type, replacing the currently subscribed handler, if any.
-
#unsubscribe(command_type, handler) ⇒ undefined
Unsubscribes the given handler from the given command type, if it is currently subscribed to the given command type.
Instance Method Details
#dispatch(command) ⇒ undefined
Dispatches the given command to the handler subscribed to its type
17 18 19 |
# File 'lib/synapse/command/command_bus.rb', line 17 def dispatch(command) raise NotImplementedError end |
#dispatch_with_callback(command, callback) ⇒ undefined
Dispatches the given command to the handler subscribed to its type and notifies the given callback of the outcome of the dispatch
28 29 30 |
# File 'lib/synapse/command/command_bus.rb', line 28 def dispatch_with_callback(command, callback) raise NotImplementedError end |
#subscribe(command_type, handler) ⇒ undefined
Subscribes the given handler to the given command type, replacing the currently subscribed handler, if any.
38 39 40 |
# File 'lib/synapse/command/command_bus.rb', line 38 def subscribe(command_type, handler) raise NotImplementedError end |
#unsubscribe(command_type, handler) ⇒ undefined
Unsubscribes the given handler from the given command type, if it is currently subscribed to the given command type.
48 49 50 |
# File 'lib/synapse/command/command_bus.rb', line 48 def unsubscribe(command_type, handler) raise NotImplementedError end |