[][src]Module workerpool::thunk

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 std::sync::mpsc::channel;
use workerpool::Pool;
use workerpool::thunk::{Thunk, ThunkWorker};

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 T that is also Sized + Send.

ThunkWorker

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