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 _ in 0..n_jobs {
    pool.execute_to(tx.clone(), Thunk::of(|| 1i32));
}

assert_eq!(rx.iter().take(n_jobs).fold(0, |a, b| a + b), 8);

Structs

Thunk

This type represents an argumentless function with return type T that is also Sized + Send.

ThunkWorker

[ThunkWorker] implements Worker that executes on Thunk<T>.