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 futher
computations can be chained along with it as well.
extern crate futures;
extern crate futures_cpupool;
use std::sync::mpsc::channel;
use futures::{Future, Task};
use futures_cpupool::CpuPool;
# fn long_running_computation() -> u32 { 2 }
# fn long_running_computation2(a: u32) -> u32 { a }
# fn main() {
let pool = CpuPool::new(4);
let a = pool.execute(long_running_computation);
let b = pool.execute(|| long_running_computation2(100));
let c = a.join(b).map(|(a, b)| a + b);
let (tx, rx) = channel();
Task::new().run(c.then(move |res| {
tx.send(res).unwrap();
Ok(())
}).boxed());
let res = rx.recv().unwrap();
println!("{:?}", res);
# }