Class: Synapse::Command::AsynchronousCommandBus

Inherits:
SimpleCommandBus show all
Defined in:
lib/synapse/command/async_command_bus.rb

Overview

TODO:

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

Attributes inherited from SimpleCommandBus

#filters, #interceptors, #rollback_policy

Instance Method Summary collapse

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_poolContender::Pool::ThreadPoolExecutor

Pool of worker threads that dispatch commands from a queue

Returns:

  • (Contender::Pool::ThreadPoolExecutor)


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

Parameters:

Returns:

  • (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

#shutdownundefined

Shuts down the command bus, waiting until all tasks are finished

Returns:

  • (undefined)


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

Returns:

  • (undefined)


34
35
36
# File 'lib/synapse/command/async_command_bus.rb', line 34

def shutdown!
  @thread_pool.shutdown!
end