class Startback::Bus::Memory::Sync

Synchronous implementation of the Bus abstraction, for use between components sharing the same process.

Public Class Methods

new() click to toggle source
# File lib/startback/bus/memory/sync.rb, line 11
def initialize
  @listeners = {}
end

Public Instance Methods

emit(event) click to toggle source
# 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) click to toggle source
# 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