2 unstable releases

0.2.0 Apr 30, 2024
0.1.0 Apr 29, 2024

#458 in Algorithms

Download history 692/week @ 2024-04-29

692 downloads per month

MIT/Apache

10KB
185 lines

ordq

Order keeping job processing queue

Example:

struct Add;

impl ordq::Work for Add {
    type I = (i32, i32);
    type O = i32;

    fn run(&mut self, x: Self::I) -> Self::O {
        x.0 + x.1
    }
}

# fn test_jobq() {
let (tx, rx) = ordq::new(1024, vec![Add, Add]);

tx.send((1, 2));
tx.send((3, 4));

tx.close();

assert_eq!(rx.recv(), Some(Ok(3)));
assert_eq!(rx.recv(), Some(Ok(7)));
assert_eq!(rx.recv(), None);
assert_eq!(rx.recv(), None);
# }

lib.rs:

Order keeping job processing queue.

This module provides a multithreaded worker pool that processes tasks while keeping the order of outputs.

Example:

struct Add;

impl ordq::Work for Add {
    type I = (i32, i32);
    type O = i32;

    fn run(&mut self, x: Self::I) -> Self::O {
        x.0 + x.1
    }
}

let (tx, rx) = ordq::new(1024, vec![Add, Add]);

tx.send((1, 2));
tx.send((3, 4));
tx.send((5, 6));

tx.close();

assert_eq!(rx.recv(), Some(Ok(3)));
assert_eq!(rx.recv(), Some(Ok(7)));
assert_eq!(rx.recv(), Some(Ok(11)));
assert_eq!(rx.recv(), None);
assert_eq!(rx.recv(), None);

Dependencies

~0.6–1.1MB
~24K SLoC