Class: Startback::Bus::Memory::Async
- Inherits:
-
Object
- Object
- Startback::Bus::Memory::Async
- Includes:
- Support::Robustness
- Defined in:
- lib/startback/bus/memory/async.rb
Overview
Asynchronous implementation of the Bus abstraction, for use between components sharing the same process.
This implementation actually calls listeners synchronously (it mays) but hides error raised by them. See Bus::Bunny::Async for another implementation that is truly asynchronous and relies on RabbitMQ.
Constant Summary collapse
- DEFAULT_OPTIONS =
{ }
Instance Method Summary collapse
- #emit(event) ⇒ Object
-
#initialize(options = {}) ⇒ Async
constructor
A new instance of Async.
- #listen(type, processor = nil, listener = nil, &bl) ⇒ Object
Methods included from Support::Robustness
#log, #monitor, #stop_errors, #try_max_times
Constructor Details
#initialize(options = {}) ⇒ Async
Returns a new instance of Async.
18 19 20 21 |
# File 'lib/startback/bus/memory/async.rb', line 18 def initialize( = {}) @options = DEFAULT_OPTIONS.merge() @listeners = {} end |
Instance Method Details
#emit(event) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/startback/bus/memory/async.rb', line 23 def emit(event) (@listeners[event.type.to_s] || []).each do |l| stop_errors(self, "emit", event) { l.call(event) } end end |
#listen(type, processor = nil, listener = nil, &bl) ⇒ Object
31 32 33 34 35 |
# File 'lib/startback/bus/memory/async.rb', line 31 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 |