Class: Startback::Event::Bus::Memory::Sync
- Inherits:
-
Object
- Object
- Startback::Event::Bus::Memory::Sync
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
#log, #monitor, #stop_errors, #try_max_times
Constructor Details
#initialize ⇒ Sync
12
13
14
|
# File 'lib/startback/event/bus/memory/sync.rb', line 12
def initialize
@listeners = {}
end
|
Instance Method Details
#connect ⇒ Object
16
17
|
# File 'lib/startback/event/bus/memory/sync.rb', line 16
def connect
end
|
#emit(event) ⇒ Object
19
20
21
22
23
|
# File 'lib/startback/event/bus/memory/sync.rb', line 19
def emit(event)
(@listeners[event.type.to_s] || []).each do |l|
l.call(event)
end
end
|
#listen(type, processor = nil, listener = nil, &bl) ⇒ Object
25
26
27
28
29
|
# File 'lib/startback/event/bus/memory/sync.rb', line 25
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
|