celluloid/celluloid — pull request #52 by grantr (2012-06-22 19:55:19+00:00)
Title: Notifications for actors

This branch adds a simple pubsub system for celluloid actors. The code is a simplified and tweaked version of ActiveSupport::Notifications.

Actors need to include Celluloid::Notifications to participate. They can subscribe(topic, method) and publish(topic, *payload). Notifications are sent to subscribers as async calls.

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.