Class: Synapse::Command::AsynchronousCommandBus
- Inherits:
-
SimpleCommandBus
- Object
- CommandBus
- SimpleCommandBus
- Synapse::Command::AsynchronousCommandBus
- Defined in:
- lib/synapse/command/async_command_bus.rb
Overview
Look into non-blocking circular buffers or LMAX Disruptor
Command bus that uses a thread pool to asynchronously execute commands, invoking the given callback when execution is completed or resulted in an error
Instance Attribute Summary collapse
-
#thread_pool ⇒ Contender::Pool::ThreadPoolExecutor
Pool of worker threads that dispatch commands from a queue.
Attributes inherited from SimpleCommandBus
#filters, #interceptors, #rollback_policy
Instance Method Summary collapse
- #dispatch_with_callback(command, callback) ⇒ undefined
-
#shutdown ⇒ undefined
Shuts down the command bus, waiting until all tasks are finished.
-
#shutdown! ⇒ undefined
Shuts down the command bus without waiting for tasks to finish.
Methods inherited from SimpleCommandBus
#dispatch, #initialize, #subscribe, #unsubscribe
Methods inherited from CommandBus
#dispatch, #subscribe, #unsubscribe
Constructor Details
This class inherits a constructor from Synapse::Command::SimpleCommandBus
Instance Attribute Details
#thread_pool ⇒ Contender::Pool::ThreadPoolExecutor
Pool of worker threads that dispatch commands from a queue
10 11 12 |
# File 'lib/synapse/command/async_command_bus.rb', line 10 def thread_pool @thread_pool end |
Instance Method Details
#dispatch_with_callback(command, callback) ⇒ undefined
16 17 18 19 20 |
# File 'lib/synapse/command/async_command_bus.rb', line 16 def dispatch_with_callback(command, callback) @thread_pool.execute do super command, callback end end |
#shutdown ⇒ undefined
Shuts down the command bus, waiting until all tasks are finished
26 27 28 |
# File 'lib/synapse/command/async_command_bus.rb', line 26 def shutdown @thread_pool.shutdown end |
#shutdown! ⇒ undefined
Shuts down the command bus without waiting for tasks to finish
34 35 36 |
# File 'lib/synapse/command/async_command_bus.rb', line 34 def shutdown! @thread_pool.shutdown! end |