Skip to content

block_on

Runs future to completion on the current thread and returns its output.

A minimal executor with no dependency: it polls the future, and while it is pending parks the thread until the future’s waker is called. There is no reactor, timer or thread pool, so it suits futures that are purely computational or woken by another thread (channels, locks, your own Waker users). A future that needs a specific runtime (tokio’s sockets or timers, for instance) must run in that runtime instead, and blocking inside one would deadlock it.

use helpers4::future::block_on;

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"] }
pub fn block_on<F: Future>(future: F) -> F::Output
ParameterTypeDescription
futureFThe future to run.

F::Output — The output of future.

use helpers4::future::block_on;

let answer = block_on(async { 40 + 2 });
assert_eq!(answer, 42);

src/future/block_on.rs