Sha256: 5b4e49e96e17635dafceac956a485ce0b4904679cd3616f57333c22758f4b2e5
Contents?: true
Size: 1.28 KB
Versions: 33
Compression:
Stored size: 1.28 KB
Contents
module Startback class Event class Bus module Memory # # 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. # class Async include Support::Robustness DEFAULT_OPTIONS = { } def initialize(options = {}) @options = DEFAULT_OPTIONS.merge(options) @listeners = {} end def connect end def emit(event) (@listeners[event.type.to_s] || []).each do |l| stop_errors(self, "emit", event) { l.call(event) } end end 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 end # class Sync end # module Memory end # class Bus end # class Event end # module Startback
Version data entries
33 entries across 33 versions & 3 rubygems