Skip to main content

delay

Function delay 

Source
pub async fn delay(ct: &CancellationToken, duration: Duration) -> bool
Expand description

Wait for duration, returning false as soon as ct is cancelled.

This is the interruptible counterpart of tokio::time::sleep: a worker that sleeps for 30s stops within milliseconds of a shutdown.

ⓘ
while !ct.is_cancelled() {
    work().await?;
    if !delay(&ct, interval).await {
        break; // cancelled
    }
}