Class: Startback::Bus::Memory::Sync
- Inherits:
-
Object
- Object
- Startback::Bus::Memory::Sync
- Includes:
- Support::Robustness
- Defined in:
- lib/startback/bus/memory/sync.rb
Overview
Synchronous implementation of the Bus abstraction, for use between components sharing the same process.
Instance Method Summary collapse
- #emit(event) ⇒ Object
-
#initialize ⇒ Sync
constructor
A new instance of Sync.
- #listen(type, processor = nil, listener = nil, &bl) ⇒ Object
Methods included from Support::Robustness
#log, #monitor, #stop_errors, #try_max_times
Constructor Details
#initialize ⇒ Sync
Returns a new instance of Sync.
11 12 13 |
# File 'lib/startback/bus/memory/sync.rb', line 11 def initialize @listeners = {} end |
Instance Method Details
#emit(event) ⇒ Object
15 16 17 18 19 |
# File 'lib/startback/bus/memory/sync.rb', line 15 def emit(event) (@listeners[event.type.to_s] || []).each do |l| l.call(event) end end |
#listen(type, processor = nil, listener = nil, &bl) ⇒ Object
21 22 23 24 25 |
# File 'lib/startback/bus/memory/sync.rb', line 21 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 |