Skip to main content

Module blocking

Module blocking 

Source
Available on crate feature blocking only.
Expand description

Synchronous interoperability for runtime-agnostic futures.

This module bridges synchronous Rust code to a single future. Enable it with the opt-in blocking Cargo feature.

FutureExt lets synchronous callers wait until a future completes, either indefinitely or until a timeout elapses:

use std::time::Duration;

use asyncband::blocking::FutureExt as _;

assert_eq!(async { 42 }.block_on(), 42);
assert_eq!(async { 42 }.wait_timeout(Duration::ZERO), Some(42));

Callers that prefer function syntax can invoke the same trait method with UFCS, for example FutureExt::block_on(future); there is no separate free-function entry point.

§Execution model

These operations use a lightweight single-future executor, not a general-purpose async runtime. They poll the future on the calling thread and wait on a private parker while the future is pending. Recursive calls receive a separate parker, and the parker does not share the notification token used by thread::park.

No timer, I/O, or task scheduler is provided. Futures that depend on a runtime-specific driver, such as Tokio timers, I/O resources, or spawned tasks, may therefore make no progress. This module is intended for runtime-agnostic futures, including the primitives provided by this crate.

§Executor threads

Do not call FutureExt::block_on or FutureExt::wait_timeout from an async executor task. Blocking an executor thread can starve other tasks and can deadlock when the future waits on work assigned to that executor. Call these methods only from synchronous code, such as main, a dedicated thread, or a sync-to-async boundary.

Traits§

FutureExt
Extension methods for waiting on a future from synchronous code.