Module: Signals::Publisher::InstanceMethods
- Defined in:
- lib/signals/publisher.rb
Instance Method Summary collapse
-
#broadcast(event, *args) ⇒ void
Broadcasts an event to all of the subscribed listeners.
-
#listeners ⇒ Set
All of the listeners subscribed to a publisher.
-
#on(event, &block) ⇒ void
Creates a one off listener that will respond to the event provided only.
-
#subscribe(listener) ⇒ void
Subscribe a listener to the publisher.
-
#unsubscribe(listener) ⇒ void
Unsubscribe a listener from the publisher.
Instance Method Details
#broadcast(event, *args) ⇒ void
This method returns an undefined value.
Broadcasts an event to all of the subscribed listeners
12 13 14 15 16 17 |
# File 'lib/signals/publisher.rb', line 12 def broadcast(event, *args) listeners.each do |listener| listener.execute_event(event, *args) end nil end |
#listeners ⇒ Set
All of the listeners subscribed to a publisher
45 46 47 |
# File 'lib/signals/publisher.rb', line 45 def listeners @listeners ||= Set.new end |
#on(event, &block) ⇒ void
This method returns an undefined value.
Creates a one off listener that will respond to the event provided only
22 23 24 25 |
# File 'lib/signals/publisher.rb', line 22 def on(event, &block) listeners.add(BlockListener.new(event, &block)) nil end |
#subscribe(listener) ⇒ void
This method returns an undefined value.
Subscribe a listener to the publisher
30 31 32 33 |
# File 'lib/signals/publisher.rb', line 30 def subscribe(listener) listeners.add(listener) nil end |
#unsubscribe(listener) ⇒ void
This method returns an undefined value.
Unsubscribe a listener from the publisher
38 39 40 41 |
# File 'lib/signals/publisher.rb', line 38 def unsubscribe(listener) listeners.delete(listener) nil end |