#blocking #queue #channel #thread-spawn #mspc

blockingqueue

A very very simple wrapper around Rust's mspc channel to work as a blocking queue

2 releases

0.1.1 Oct 29, 2020
0.1.0 Oct 26, 2020

#1772 in Concurrency

Download history 15/week @ 2025-10-13 17/week @ 2025-10-20 28/week @ 2025-10-27 35/week @ 2025-11-03 58/week @ 2025-11-10 18/week @ 2025-11-17 3/week @ 2025-11-24 31/week @ 2025-12-01 12/week @ 2025-12-08 20/week @ 2025-12-15 10/week @ 2025-12-22 5/week @ 2025-12-29 142/week @ 2026-01-05 91/week @ 2026-01-12 54/week @ 2026-01-19 80/week @ 2026-01-26

367 downloads per month

MIT/Apache

4KB
60 lines

BlockingQueue

A very very simple wrapper around Rust's mspc channel to work as a blocking queue.

Usage

Here is a little example on how to use it:

use blockingqueue::BlockingQueue;
use std::{thread, time};

fn main() {
    let bq = BlockingQueue::new();

    let bq_clone1 = bq.clone();
    thread::spawn(move || {
        thread::sleep(time::Duration::from_millis(100));
        bq_clone1.push(123);
        bq_clone1.push(456);
        bq_clone1.push(789);
    });

    let bq_clone2 = bq.clone();
    thread::spawn(move || {
        thread::sleep(time::Duration::from_millis(400));
        bq_clone2.push(321);
        bq_clone2.push(654);
        bq_clone2.push(987);
    });

    let bq_clone3 = bq.clone();
    let read_three_thread = thread::spawn(move || {
        for _ in 0..3 {
            println!("Popped in child thread: {}", bq_clone3.pop());
        }
    });

    for _ in 0..3 {
        println!("Popped in parent thread: {}", bq.pop());
    }

    read_three_thread.join().unwrap();

    println!("I will wait forever here...");
    println!("{}", bq.pop());
}

No runtime deps