Struct task_queue::TaskQueue [] [src]

pub struct TaskQueue {
    // some fields omitted
}

Methods

impl TaskQueue
[src]

fn new() -> TaskQueue

Create new task queue with 10 threads

fn with_threads(min: usize, max: usize) -> TaskQueue

Create new task quque with selected threads count

fn enqueue<F>(&mut self, f: F) -> Result<()TaskQueueError> where F: Fn() + Send + 'static

Schedule task in queue ``` rust extern crate task_queue;

let mut queue = task_queue::TaskQueue::new();

for _ in 0..10 { queue.enqueue(move || { println!("Hi from pool") }).unwrap(); }

queue.stop_wait();

fn stop(self) -> Vec<JoinHandle<()>>

Stops tasks queue work. All task in queue will be completed by threads. Method not block current thread work, but returns threads joinHandles.

Examples

extern crate task_queue;

let mut queue = task_queue::TaskQueue::new();

for _ in 0..10 {
   queue.enqueue(move || {
       println!("Hi from pool")
   }).unwrap();
}
let handles = queue.stop();
for h in handles {
    h.join().unwrap();
}

fn stop_wait(self)

Stops tasks queue work. All task in queue will be completed by threads. Method block current thread work.

Examples

extern crate task_queue;

let mut queue = task_queue::TaskQueue::new();

for _ in 0..10 {
   queue.enqueue(move || {
       println!("Hi from pool")
   }).unwrap();
}
queue.stop_wait();

fn stop_immediately(self) -> Vec<Task>

Stops tasks queue work immediately and return are not completed tasks Stops tasks queue work.

Examples

extern crate task_queue;

let mut queue = task_queue::TaskQueue::new();

for _ in 0..10 {
   queue.enqueue(move || {
       println!("Hi from pool")
   }).unwrap();
}
let not_completed = queue.stop_immediately();
for t in &not_completed {
    t.run();
}

fn get_threads_count(&self) -> usize

Returns current threads count

fn get_max_threads(&self) -> usize

Return max threads count

fn get_min_threads(&self) -> usize

Return min threads count

fn set_spawn_policy(&mut self, policy: Box<SpawnPolicy>)

Sets a policy for controlling the amount of threads

fn tasks_count(&self) -> usize

Gets tasks count in queue

Trait Implementations

impl Drop for TaskQueue
[src]

fn drop(&mut self)

All task in queue will be completed by threads.