class Observed::BasicEventBus

Public Class Methods

new() click to toggle source
# File lib/observed/basic_event_bus.rb, line 6
def initialize
  @monitor = ::Monitor.new
  @subscribers = []
end

Public Instance Methods

emit(tag, *params) click to toggle source
# File lib/observed/basic_event_bus.rb, line 10
def emit(tag, *params)
  handle_event(tag, *params)
end
on_receive(pattern, &block) click to toggle source
# File lib/observed/basic_event_bus.rb, line 14
def on_receive(pattern, &block)
  @monitor.synchronize do
    @subscribers.push [pattern, block]
  end
end

Private Instance Methods

handle_event(tag, *params) click to toggle source
# File lib/observed/basic_event_bus.rb, line 22
def handle_event(tag, *params)
  @monitor.synchronize do
    @subscribers.each do |pattern, s|
      if pattern.match(tag)
        s.call *params
      end
    end
  end
end