Crate ordq

source ·
Expand description

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);

Structs§

  • Receives job output from the thread pool.
  • Error when a worker failed to send the output.
  • Error when a sender failed to send the input because of receiving end is dropped
  • The input sender that sends job input to the workers.
  • Worker stats

Traits§

  • Work can do some work with input I, and output O.

Functions§

  • Create a worker thread pool with the given queue capacity and workers.