Skip to content

future

Runtime-neutral helpers for Futures, built on the standard library only.

No reactor, timer or thread pool is involved, so none of it depends on tokio, async-std or any other runtime: block_on runs a future on the current thread, join and join_all combine futures on one task, and now_or_never and yield_now are the small building blocks around them.

Cargo feature future (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features future

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.6", default-features = false, features = ["future"] }

Import path: helpers4::future.

ItemWhat it does
block_onRuns future to completion on the current thread and returns its output.
joinRuns two futures concurrently and completes with both outputs, once both are done.
join_allRuns any number of futures concurrently and completes with all their outputs, in the order the futures were given.
now_or_neverPolls future exactly once and returns its output if it was already ready.
yield_nowA future that gives other tasks a turn: it is pending once, then completes.