Crate task_queue [] [src]

Task queue The implementation of the thread pool for Rust.

Example

extern crate task_queue;

use std::sync::{ Arc, Mutex };

let data = Arc::new(Mutex::new(0));
let mut queue = task_queue::TaskQueue::new();

for _ in 0..1000 {
   let clone = data.clone();

   queue.enqueue(move || {
       let mut guard = clone.lock().unwrap();
       *guard += 1;
   }).unwrap();
}

let not_executed_tasks = queue.stop_immediately().unwrap();
for t in &not_executed_tasks {
    t.run();
}

Library supports dynamic control over the number of threads. For implement it you should use SpawnPolicy trait.

For example StaticSpawnPolicy implementation:

Example

use task_queue::TaskQueue;
use task_queue::spawn_policy::SpawnPolicy;

pub struct StaticSpawnPolicy;

impl SpawnPolicy for StaticSpawnPolicy {
    fn get_count(&self, queue: &TaskQueue) -> usize {
        queue.get_max_threads()
    }
}

Modules

error

TaskQueue error.

spawn_policy

Trait that controls the number of threads.

Structs

Task
TaskQueue