Crates.io | rdispatcher |
lib.rs | rdispatcher |
version | 0.1.0 |
source | src |
created_at | 2015-06-15 20:13:26.912649 |
updated_at | 2015-12-11 23:55:29.371301 |
description | Dispatcher for Rust, broadcast and subscribe many to many |
homepage | http://www.github.com/timonv/rdispatcher |
repository | http://www.github.com/timonv/rdispatcher |
max_upload_size | |
id | 2391 |
size | 9,845 |
The Dispatcher allows you to send messages from multiple broadcasters to multiple receivers. When a lot of messages get passed around a threaded application, centralizing where messages flow through can create much wanted oversight.
The types of messages that get passed around are strongly typed, required by you to setup, and the messages themselves are strings.
Add to your Cargo.toml
rdispatcher = "*"
And run cargo install
A simple example:
let mut dispatcher = Dispatcher::new();
let sub = TestSubscriber::new();
let mut brd = TestBroadcaster::new();
dispatcher.register_broadcaster(&mut brd);
dispatcher.register_subscriber(&sub, OutgoingMessage);
dispatcher.start();
brd.broadcast(OutgoingMessage, "Hello world!".to_string());
let message = sub.receiver.recv().unwrap();
assert_eq!(message.dispatch_type, OutgoingMessage);
assert_eq!(message.payload, "Hello world!");
For several full examples, checkout the tests in lib.rs