class Startback::Bus::Memory::Async
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.
Constants
- DEFAULT_OPTIONS
Public Class Methods
new(options = {})
click to toggle source
# File lib/startback/bus/memory/async.rb, line 18 def initialize(options = {}) @options = DEFAULT_OPTIONS.merge(options) @listeners = {} end
Public Instance Methods
emit(event)
click to toggle source
# 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)
click to toggle source
# 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