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§
- Receiver
- Receives job output from the thread pool.
- Recv
Error - Error when a worker failed to send the output.
- Send
Error - Error when a sender failed to send the input because of receiving end is dropped
- Sender
- The input sender that sends job input to the workers.
- Stats
- Worker stats
Traits§
- Work
Work
can do some work with inputI
, and outputO
.
Functions§
- new
- Create a worker thread pool with the given queue capacity and workers.