Class: Synapse::Command::CommandBus Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse/command/command_bus.rb

Overview

This class is abstract.

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

SimpleCommandBus

Instance Method Summary collapse

Instance Method Details

#dispatch(command) ⇒ undefined

This method is abstract.

Dispatches the given command to the handler subscribed to its type

Parameters:

Returns:

  • (undefined)

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/synapse/command/command_bus.rb', line 17

def dispatch(command)
  raise NotImplementedError
end

#dispatch_with_callback(command, callback) ⇒ undefined

This method is abstract.

Dispatches the given command to the handler subscribed to its type and notifies the given callback of the outcome of the dispatch

Parameters:

Returns:

  • (undefined)

Raises:

  • (NotImplementedError)


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.

Parameters:

Returns:

  • (undefined)

Raises:

  • (NotImplementedError)


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.

Parameters:

Returns:

  • (undefined)

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/synapse/command/command_bus.rb', line 48

def unsubscribe(command_type, handler)
  raise NotImplementedError
end