Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
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.
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.
require 'celluloid/autostart' to start default notifier.
Check out the