pub-sub

A basic publish/subscribe channel

2 stable releases

Uses old Rust 2015

2.0.0 Feb 28, 2017
1.0.0 Sep 4, 2016
Download history 85/week @ 2024-07-19 105/week @ 2024-07-26 44/week @ 2024-08-02 139/week @ 2024-08-09 105/week @ 2024-08-16 77/week @ 2024-08-23 118/week @ 2024-08-30 84/week @ 2024-09-06 54/week @ 2024-09-13 89/week @ 2024-09-20 39/week @ 2024-09-27 18/week @ 2024-10-04 20/week @ 2024-10-11 17/week @ 2024-10-18 10/week @ 2024-10-25 15/week @ 2024-11-01

64 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–450KB