Module workerpool::thunk
[−]
[src]
Provides a Worker for simple stateless functions that have no arguments.
The stateless ThunkWorker<T> executes on inputs of Thunk<T>, effectively
argumentless functions that are Sized + Send.
These thunks are creates by wrapping functions which return T with Thunk::of.
Examples
use workerpool::Pool; use workerpool::thunk::{Thunk, ThunkWorker}; use std::sync::mpsc::channel; let n_workers = 4; let n_jobs = 8; let pool = Pool::<ThunkWorker<i32>>::new(n_workers); let (tx, rx) = channel(); for i in 0..n_jobs { pool.execute_to(tx.clone(), Thunk::of(move || i * i)); } assert_eq!(140, rx.iter().take(n_jobs as usize).sum());
Structs
| Thunk |
This type represents an argumentless function with return type |
| ThunkWorker |