Skip to content

yield_now

A future that gives other tasks a turn: it is pending once, then completes.

The first poll wakes the task straight away and returns Pending, so an executor that runs many tasks can schedule the others before resuming this one. Call it inside a long computation in an async block to keep it from monopolising its thread.

use helpers4::future::yield_now;

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 yield_now() -> impl Future<Output = ()>

impl Future<Output = ()> — A future that completes on its second poll.

use helpers4::future::{block_on, yield_now};

block_on(async {
    yield_now().await;
});

src/future/yield_now.rs