Crates.io | futures-cputask |
lib.rs | futures-cputask |
version | 0.3.0 |
source | src |
created_at | 2019-10-22 10:47:46.060243 |
updated_at | 2019-11-07 16:43:41.868381 |
description | Turn synchronous CPU-bound tasks into futures |
homepage | |
repository | https://git.darkkirb.de/root/futures-cputask |
max_upload_size | |
id | 174650 |
size | 12,511 |
This library allows you to run long-running CPU-bound tasks on a secondary thread pool and receive a future you can await on.
Uses Futures 0.3.0
For Async/Await
Runs tasks on a secondary threadpool to avoid blocking one of the main executor threads
Supports the threadpool from threadpool
and uvth
using their respective cargo feature
Has traits for allowing interoperability with other threadpool implementations
Contains an optional custom attribute async_task
to turn a regular function into an async function using this crate
(Note: currently this feature only works with the threadpool
and uvth
threadpools)
Add this to your Cargo.toml
:
futures-cputask = "0.3.0"
if you want to use the custom attribute, add this:
[dependencies.futures-cputask]
version = "0.3.0"
features = ["derive"]
use futures_cputask::async_task;
#[async_task]
fn long_running_task() -> i64 {
(0..100_000_000).fold(0i64, |a, b| a.wrapping_add(b))
}
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.