[][src]Crate tasque

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

Modules

metrics

Metrics exposed for prometheus.

Structs

TaskQueue

Task queue.

TaskQueueBuilder

TaskQueue builder.