Class: Startback::Event::Bus::Memory::Sync

Inherits:
Object
  • Object
show all
Includes:
Support::Robustness
Defined in:
lib/startback/event/bus/memory/sync.rb

Overview

Synchronous implementation of the Bus abstraction, for use between components sharing the same process.

Instance Method Summary collapse

Methods included from Support::Robustness

#log, #monitor, #stop_errors, #try_max_times

Constructor Details

#initializeSync

Returns a new instance of Sync.



12
13
14
# File 'lib/startback/event/bus/memory/sync.rb', line 12

def initialize
  @listeners = {}
end

Instance Method Details

#connectObject



16
17
# File 'lib/startback/event/bus/memory/sync.rb', line 16

def connect
end

#connected?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/startback/event/bus/memory/sync.rb', line 19

def connected?
  true
end

#emit(event) ⇒ Object



23
24
25
26
27
# File 'lib/startback/event/bus/memory/sync.rb', line 23

def emit(event)
  (@listeners[event.type.to_s] || []).each do |l|
    l.call(event)
  end
end

#listen(type, processor = nil, listener = nil, &bl) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
# File 'lib/startback/event/bus/memory/sync.rb', line 29

def listen(type, processor = nil, listener = nil, &bl)
  raise ArgumentError, "A listener must be provided" unless listener || bl
  @listeners[type.to_s] ||= []
  @listeners[type.to_s] << (listener || bl)
end