2 stable releases
Uses old Rust 2015
2.0.0 | Feb 28, 2017 |
---|---|
1.0.0 | Sep 4, 2016 |
163 downloads per month
Used in 2 crates
7KB
93 lines
pub-sub
A basic publish/subscribe channel in Rust.
API Documentation
License
Licensed under either of
- GNU Lesser General Public License v3.0 (LICENSE-LGPL or https://www.gnu.org/licenses/lgpl-3.0.en.html)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
lib.rs
:
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 channel = pub_sub::PubSub::new();
let mut handles = vec![];
for _ in 0..16 {
let recv = channel.subscribe();
handles.push(thread::spawn(move || {
for _ in 0..16 {
println!("recevied {}", recv.recv().unwrap());
}
}));
}
for _ in 0..16 {
let channel = channel.clone();
handles.push(thread::spawn(move || {
let msg_id = Uuid::new_v4();
println!(" sent {}", msg_id);
channel.send(msg_id).unwrap();
}));
}
while let Some(handle) = handles.pop() {
handle.join().unwrap();
}
}
Dependencies
~300–470KB