[][src]Crate futures_cpupool

A simple crate for executing work on a thread pool, and getting back a future.

This crate provides a simple thread pool abstraction for running work externally from the current thread that's running. An instance of Future is handed back to represent that the work may be done later, and further computations can be chained along with it as well.

extern crate futures;
extern crate futures_cpupool;

use futures::Future;
use futures_cpupool::CpuPool;


// Create a worker thread pool with four threads
let pool = CpuPool::new(4);

// Execute some work on the thread pool, optionally closing over data.
let a = pool.spawn(long_running_future(2));
let b = pool.spawn(long_running_future(100));

// Express some further computation once the work is completed on the thread
// pool.
let c = a.join(b).map(|(a, b)| a + b).wait().unwrap();

// Print out the result
println!("{:?}", c);

Structs

Builder

Thread pool configuration object

CpuFuture

The type of future returned from the CpuPool::spawn function, which proxies the futures running on the thread pool.

CpuPool

A thread pool intended to run CPU intensive work.