Struct task_queue::TaskQueue
[−]
[src]
pub struct TaskQueue { /* fields omitted */ }
Methods
impl TaskQueue
[src]
fn new() -> Self
Create new task queue with 10 threads.
fn with_threads(min: usize, max: usize) -> Result<Self, TaskQueueError>
Create new task queue with selected threads count.
fn enqueue<F>(&mut self, f: F) -> Result<(), TaskQueueError> where
F: Fn() + Send + 'static,
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 ¬_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.