Struct worker::Worker
[−]
[src]
pub struct Worker<T> { /* fields omitted */ }
The worker is a thread based working queue. After you initialized the worker with the callback you want you can add items to it. As soon as the item is ready to process the callback will be called to handle the logic.
Example
let mut w = Worker::<&'static str>::single(move |r| { println!("{:?}", r); }); w.add("1"); w.add("2"); w.stop();
Methods
impl<T> Worker<T> where
T: Send + 'static,
[src]
T: Send + 'static,
fn single<F>(callback: F) -> Self where
F: Fn(T) + Send + Sync + 'static,
F: Fn(T) + Send + Sync + 'static,
Creates a single instance worker
fn multi<F>(count: usize, callback: F) -> Self where
F: Fn(T) + Send + Sync + 'static,
F: Fn(T) + Send + Sync + 'static,
Creates a multi instance worker (count defines the number of threads to be started)
fn add(&mut self, item: T)
Adds an item to the working queue
fn stop(self)
Stops the workers gracefully