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_poolThread::Pool

Pool of dispatching threads backed by a queue

Returns:

  • (Thread::Pool)


12
13
14
# File 'lib/synapse/command/async_command_bus.rb', line 12

def thread_pool
  @thread_pool
end

Instance Method Details

#dispatch_with_callback(command, callback) ⇒ undefined

Parameters:

Returns:

  • (undefined)


18
19
20
21
22
# File 'lib/synapse/command/async_command_bus.rb', line 18

def dispatch_with_callback(command, callback)
  @thread_pool.process do
    super command, callback
  end
end

#shutdownundefined

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

Returns:

  • (undefined)


28
29
30
# File 'lib/synapse/command/async_command_bus.rb', line 28

def shutdown
  @thread_pool.shutdown
end

#shutdown!undefined

Shuts down the command bus without waiting for tasks to finish

Returns:

  • (undefined)


36
37
38
# File 'lib/synapse/command/async_command_bus.rb', line 36

def shutdown!
  @thread_pool.shutdown!
end