This crate makes it easy to transform functions or closures into two objects: one that can be run on a thread pool, and a [Future
] on its result. Contrarily to other existing solution, starting the computation is independent from polling the future. It is entirely independent of both the thread or thread pool used to run the actual computations and the future executor.
The entry-point is [closure_future
].
Workers can be run on threads:
```rust
let (future, worker) = closurefuture(|| { // ... do some work and return a value ... "Hello!" }); std::thread::spawn(|| worker.run()); asserteq!(block_on(future), Ok("Hello!")) ```
Workers can also be run using rayon global thread-pool, using a provided helper function:
```rust
let mut futures = Vec::new(); for i in 0..10 { let future = spawnrayon(move || { // ... do some work and return a value ... i }); futures.push(future) } for (i,fut) in futures.intoiter().enumerate() { asserteq!(blockon(fut),Ok(i)); } ```