Skip to main content

block_on

Function block_on 

Source
pub fn block_on<F>(future: F) -> F::Output
where F: Future,
Expand description

Runs a future to completion on the current thread.

The future is polled in a simple park/wake loop backed by a condition variable. This works well for the workspace’s usage patterns, where futures are usually short-lived control flows rather than large, highly concurrent task graphs.

§Safety invariants

The custom RawWaker implementation below relies on three invariants:

  • every raw pointer stored in the waker originates from Arc<Parker>::into_raw
  • clone, wake, wake_by_ref, and drop balance the Arc strong count
  • the parker’s notification bit is cleared only immediately before polling, so wake-ups emitted during or after the poll are still observed by park

§Panics

Panics if writing wake-up state into the internal synchronization primitives panics, which in practice only happens if a mutex is poisoned.

§Examples

use corsa_runtime::block_on;

let value = block_on(async { 6 * 7 });
assert_eq!(value, 42);