#futures #async #future #threadpool #executor

poolparty

Added functionality for the futures::executor::ThreadPool futures executor

9 releases (4 stable)

2.0.0 Jan 3, 2021
1.0.2 Jan 3, 2021
1.0.1 Nov 29, 2020
1.0.0 Jun 11, 2020
0.1.2 Feb 27, 2020

#198 in Asynchronous

Download history 17/week @ 2021-01-13 1/week @ 2021-01-27 4/week @ 2021-02-03 25/week @ 2021-02-10 50/week @ 2021-02-17 15/week @ 2021-02-24 7/week @ 2021-03-03 12/week @ 2021-03-10 27/week @ 2021-03-24 18/week @ 2021-03-31 9/week @ 2021-04-07 13/week @ 2021-04-14 12/week @ 2021-04-21 9/week @ 2021-04-28

55 downloads per month

MIT license

10KB
134 lines

Cargo Documentation

Tiny crate providing added functionality to the futures-rs threadpool executor. The futures::future::ThreadPool executor currently has no way built in to handle panics, manually stop the pool execution or bubble up errors back to the caller. The crate works around these limitations (it might get obsolete once this open issue will be resolved).

Use cases for the crate are:

  • Stop executing futures in case any of future that runs on it faces an unrecoverable error and returns an Err().
  • Let the caller handle the error.
  • Stop the threadpool and its spawned tasks on user request.

⚠ This crate is beeing passively maintained. It works just fine for me in an existing project. However I'll be using smol as my futures executor in new projects. The smol task handles offer the same functionality (and more), rendering this crate obsolete.

Usage

The following example demonstrates the handling of a failing task:

async fn forever() -> Result<(),String> {
    loop {}
}

async fn fail(msg: String) -> Result<(),String> {
    Err(msg)
}

let mut pool = StoppableThreadPool::new()?;
let err = "fail_function_called".to_string();
pool.spawn(fail(err.clone()));
pool.spawn(forever());

assert_eq!(
    pool.observe().await.unwrap_err(),
    err
)

Have a look at the tests in lib.rs for more usage examples.

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in poolparty by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2–4MB
~79K SLoC