Function zng_task::deadline

source ·
pub fn deadline(
    deadline: impl Into<Deadline>
) -> Pin<Box<dyn Future<Output = ()> + Send + Sync>>
Expand description

A future that is Pending until the deadline is reached.

§Examples

Await 5 seconds in a spawn parallel task:

use zng_task as task;
use zng_unit::*;

task::spawn(async {
    println!("waiting 5 seconds..");
    task::deadline(5.secs()).await;
    println!("5 seconds elapsed.")
});

The future runs on an app provider timer executor, or on the futures_timer by default.

Note that deadlines from Duration starts counting at the moment this function is called, not at the moment of the first .await call.