2 stable releases

Uses old Rust 2015

2.0.0 Feb 28, 2017
1.0.0 Sep 4, 2016

#14 in #publish-subscribe

Download history 137/week @ 2024-03-13 105/week @ 2024-03-20 217/week @ 2024-03-27 243/week @ 2024-04-03 172/week @ 2024-04-10 226/week @ 2024-04-17 124/week @ 2024-04-24 56/week @ 2024-05-01 102/week @ 2024-05-08 117/week @ 2024-05-15 158/week @ 2024-05-22 95/week @ 2024-05-29 56/week @ 2024-06-05 46/week @ 2024-06-12 110/week @ 2024-06-19 89/week @ 2024-06-26

312 downloads per month
Used in 2 crates

MIT/LGPL-3.0

7KB
93 lines

pub-sub

View on crates.io

A basic publish/subscribe channel in Rust.

API Documentation

  • Latest stable: API docs for latest stable
  • Master: API docs for master branch

License

Licensed under either of


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

~285–445KB