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 141/week @ 2024-08-31 51/week @ 2024-09-07 56/week @ 2024-09-14 92/week @ 2024-09-21 35/week @ 2024-09-28 15/week @ 2024-10-05 21/week @ 2024-10-12 17/week @ 2024-10-19 12/week @ 2024-10-26 24/week @ 2024-11-02 4/week @ 2024-11-09 14/week @ 2024-11-16 18/week @ 2024-11-23 31/week @ 2024-11-30 56/week @ 2024-12-07 54/week @ 2024-12-14

163 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

~300–470KB