-
-
Notifications
You must be signed in to change notification settings - Fork 272
Notifications
Notifications let actors subscribe and publish to a topic without having to know the registry name or have a reference to other actors. Notifications are delivered to subscribed actors asynchronously.
The code is a simplified and tweaked version of ActiveSupport::Notifications.
Actors need to include Celluloid::Notifications to participate. They can subscribe(topic_string, method)
and publish(topic_string, *payload)
. Notifications are sent to subscribers as async calls.
But publish
calls can be made from outside actors also, using the Celluloid::Notifications.publish
class method, or Celluloid.publish
for short.
subscribe
returns a subscriber object that can be used to unsubscribe later. However the caveat to ActiveSupport::Notifications still applies here: the implementation is designed for long-lived subscriptions and might not be efficient for many short-lived subscriptions.
The default notifier sends notifications to all subscribers, but can be swapped out for another implementation by setting Celluloid::Notifications.notifier
. Notifiers should probably be actors since other implementations may rely on that (dcell for example may need an actor notifier for distributed pubsub).
The default notifier also links to subscribers so their subscriptions can be pruned when they die.
Add require 'celluloid/autostart'
to start default notifier.
Check out the pubsub.rb
example:
Examples in Reel:
Always feel free to:
- Visit the
#celluloid
channel on freenode. - Post a bug report or feature request.
- Ask questions on our mailing list.