7 releases
Uses old Rust 2015
0.1.5 | Aug 19, 2019 |
---|---|
0.1.4 | Jan 19, 2018 |
0.1.0 | Dec 20, 2017 |
0.0.1 | Dec 19, 2017 |
#894 in Concurrency
125 downloads per month
Used in 12 crates
(via fibers_tasque)
16KB
331 lines
tasque
A simple thread pool library for Rust.
lib.rs
:
A simple thread pool library for Rust.
Examples
Basic usage:
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
use tasque::TaskQueueBuilder;
// Creates a task queue.
// This queue spawns worker threads for executing tasks.
let queue = TaskQueueBuilder::new().worker_count(3).finish();
// Executes asynchronous tasks.
let (tx, rx) = mpsc::channel();
for (i, tx) in (0..3).map(|i| (i, tx.clone())) {
queue.enqueue(move || {
thread::sleep(Duration::from_millis(20 - i * 10));
let _ = tx.send(i);
});
}
// Waits results.
assert_eq!(rx.recv().ok(), Some(2));
assert_eq!(rx.recv().ok(), Some(1));
assert_eq!(rx.recv().ok(), Some(0));
Dependencies
~1.4–1.8MB
~43K SLoC