#thread-pool

tasque

A simple thread pool library

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

#167 in Concurrency

Download history 29/week @ 2021-04-04 25/week @ 2021-04-11 57/week @ 2021-04-18 19/week @ 2021-04-25 32/week @ 2021-05-02 11/week @ 2021-05-09 25/week @ 2021-05-16 21/week @ 2021-05-23 18/week @ 2021-05-30 25/week @ 2021-06-06 21/week @ 2021-06-13 15/week @ 2021-06-20 40/week @ 2021-06-27 36/week @ 2021-07-04 26/week @ 2021-07-11 25/week @ 2021-07-18

134 downloads per month
Used in 11 crates (via fibers_tasque)

MIT license

15KB
331 lines

tasque

tasque Documentation Build Status Code Coverage License: MIT

A simple thread pool library for Rust.

Documentation


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

~0.5–1.1MB
~26K SLoC