Struct pconvert_rust::parallelism::ThreadPool  [−][src]
pub struct ThreadPool { /* fields omitted */ }Expand description
Thread pool used in multi-threaded pconvert calls.
Implementations
Creates a thread pool with size worker threads.
pub fn execute<F>(&self, func: F) -> Receiver<ResultMessage> where
    F: FnOnce() -> ResultMessage + Send + 'static, 
pub fn execute<F>(&self, func: F) -> Receiver<ResultMessage> where
    F: FnOnce() -> ResultMessage + Send + 'static, 
Enqueues a task for execution by any of the worker threads.
Arguments
- func- The task to execute.
Return
Returns the receiver end of a channel where the result will be placed.
Examples
use pconvert_rust::parallelism::{ResultMessage, ThreadPool};
use pconvert_rust::utils::read_png_from_file;
let mut thread_pool = ThreadPool::new(10).unwrap();
let path = "path/to/file.png".to_owned();
let demultiply = false;
let result_channel = thread_pool.execute(move || ResultMessage::ImageResult(read_png_from_file(path, demultiply)));
let top = match result_channel.recv().unwrap() {
    ResultMessage::ImageResult(result) => result,
}.unwrap();Expands the thread pool to num_threads.
Creates n workers, where n = num_threads - thread_pool_size.