Trying to find a threadpool that allows to retrieve the results of thread executions.
- Had a look at threadpool - Rust.
However, there seems to be not way to retrieve the execution result of a thread: threadpool::ThreadPool - Rust.
- Had a look at tokio-threadpool: tokio_threadpool - Rust
You can retrieve the result, but the basic example does not compile:
use futures::future::{Future, lazy};
fn main() {
// Create a thread pool with default configuration values
let thread_pool = tokio_threadpool::ThreadPool::new();
thread_pool.spawn(lazy(|| {
println!("called from a worker thread");
Ok(())
}));
// Gracefully shutdown the threadpool
thread_pool.shutdown().wait().unwrap();
}
Gives:
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
--> src/main.rs:7:21
|
7 | thread_pool.spawn(lazy(|| {
| ^^^^ -- takes 0 arguments
| |
| expected closure that takes 1 argument
So assuming we fix this (doing lazy(|_|)
) we still get:
error[E0277]: the trait bound `futures::future::Lazy<[closure@src/main.rs:7:26: 10:4]>: futures::future::Future` is not satisfied
--> src/main.rs:7:21
|
7 | thread_pool.spawn(lazy(|_| {
| _____________________^
8 | | println!("called from a worker thread");
9 | | Ok(())
10 | | }));
| |____^ the trait `futures::future::Future` is not implemented for `futures::future::Lazy<[closure@src/main.rs:7:26: 10:4]>`
error[E0599]: no method named `wait` found for struct `tokio_threadpool::Shutdown` in the current scope
--> src/main.rs:13:26
|
13 | thread_pool.shutdown().wait().unwrap();
| ^^^^ method not found in `tokio_threadpool::Shutdown`
Seems to me this repo is unmaintained...
- The last solution I see is future-threadpool, but here again you don't get the return value: futures::executor::ThreadPool - Rust
Is there anything I am missing? Any solution for a working threadpool with return value out there?