Local publish/subscribe
Documentation
http://fuchsnj.github.io/rust_pubsub
Usage
This will be uploaded to crates.io when it is more stable.
For now, add the following to your Cargo.toml
[]
= "https://github.com/fuchsnj/rust_pubsub.git"
and this to your crate root:
extern crate pubsub;
##Quick Start
//create pubsub with 5 threads. These threads run notification functions.
//messages are queued indefinitely until they can be run
let pubsub = new;
//subscribe to a channel. The subscription will stay active as long
//as sub1 stays in scope
let sub1 = pubsub.subscribe;
//notify all subscribers of "channel1" with message "data1"
//This will always return immediately since messages are queued
pubsub.notify;
//notify all subscribers of "channel1" except sub1
pubsub.notify;
//notify all subscribers of "channel1" except sub1
sub1.notify_others;
//If you want to start queueing messsages for a subscription, but
//don't want to process them until after some initialization
let sub2_activator = pubsub.lazy_subscribe;
//do some initialization here...
//notifications received here are queued
pubsub.notify;
//this creates a subscription and processes any messages in the backlog
let sub2 = sub2_activator.activate;
//subscriptions can be cancelled by dropping or cancelling
drop;
sub2.cancel;