Sha256: d5d05cf199606386209773358d99cace3d383b7b396a7e029e09ea8efc0df44e
Contents?: true
Size: 874 Bytes
Versions: 9
Compression:
Stored size: 874 Bytes
Contents
module Faye module Publisher def count_subscribers(event_type) return 0 unless @subscribers and @subscribers[event_type] @subscribers[event_type].size end def add_subscriber(event_type, listener) @subscribers ||= {} list = @subscribers[event_type] ||= [] list << listener end def remove_subscriber(event_type, listener) return unless @subscribers and @subscribers[event_type] return @subscribers.delete(event_type) unless listener @subscribers[event_type].delete_if(&listener.method(:==)) end def remove_subscribers @subscribers = {} end def publish_event(event_type, *args) return unless @subscribers and @subscribers[event_type] @subscribers[event_type].each do |listener| listener.call(*args) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems