Crate pub_sub [−] [src]
A basic publish/subscribe channel.
Usage
Add to crate dependencies:
[dependencies]
pub-sub = "*"
Import in crate root:
extern crate pub_sub;
Example
extern crate pub_sub; extern crate uuid; use std::thread; use uuid::Uuid; fn main() { let (send, recv) = pub_sub::new(); // send: pub_sub::Sender<Uuid> // recv: pub_sub::Receiver<Uuid> for _ in 0..16 { let recv = recv.clone(); thread::spawn(move || { while let Ok(msg) = recv.recv() { println!("recevied {}", msg); } }); } for _ in 0..16 { let send = send.clone(); thread::spawn(move || { let msg_id = Uuid::new_v4(); println!(" sent {}", msg_id); send.send(msg_id); }); } }
Structs
Receiver |
Receiver component of a pub/sub channel. |
Sender |
Sending component of a pub/sub channel. |
Functions
new |
Create a pub/sub channel |