Class: Asynchronic::Notifier::Broadcaster
- Inherits:
-
Object
- Object
- Asynchronic::Notifier::Broadcaster
- Defined in:
- lib/asynchronic/notifier/broadcaster.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Broadcaster
constructor
A new instance of Broadcaster.
- #publish(pid, event, data = nil) ⇒ Object
- #subscribe(pid, event, &block) ⇒ Object
- #unsubscribe(subscription_id) ⇒ Object
- #unsubscribe_all ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Broadcaster
Returns a new instance of Broadcaster.
5 6 7 8 |
# File 'lib/asynchronic/notifier/broadcaster.rb', line 5 def initialize(={}) [:logger] ||= Asynchronic.logger @broadcaster = ::Broadcaster.new end |
Instance Method Details
#publish(pid, event, data = nil) ⇒ Object
10 11 12 |
# File 'lib/asynchronic/notifier/broadcaster.rb', line 10 def publish(pid, event, data=nil) broadcaster.publish DataStore::Key[pid][event], data end |
#subscribe(pid, event, &block) ⇒ Object
14 15 16 17 18 |
# File 'lib/asynchronic/notifier/broadcaster.rb', line 14 def subscribe(pid, event, &block) broadcaster.subscribe DataStore::Key[pid][event] do |data| block.call data end end |
#unsubscribe(subscription_id) ⇒ Object
20 21 22 |
# File 'lib/asynchronic/notifier/broadcaster.rb', line 20 def unsubscribe(subscription_id) broadcaster.unsubscribe subscription_id end |
#unsubscribe_all ⇒ Object
24 25 26 |
# File 'lib/asynchronic/notifier/broadcaster.rb', line 24 def unsubscribe_all broadcaster.unsubscribe_all end |