Struct task_queue::TaskQueue [] [src]

pub struct TaskQueue {
    // some fields omitted
}

Methods

impl TaskQueue
[src]

fn new() -> Self

Create new task queue with 10 threads.

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

Create new task quque with selected threads count.

Panics

When min <= 0

When max <= 0

When max < min

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

Schedule task in queue

Example

extern crate task_queue;

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

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

Panics

If spawn policy returned illegal number of threads.

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.

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 set_spawn_policy(&mut self, policy: Box<SpawnPolicy>)

Sets a policy for controlling the amount of threads

fn get_threads_count(&self) -> usize

Returns current threads count

fn get_threads_max(&self) -> usize

Return max threads count

fn get_threads_min(&self) -> usize

Return min threads count

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.