expression

Async sleep: suspend without blocking the worker

A timer future suspends the calling task until its deadline is reached. Other ready tasks may progress while it waits. This fixture uses a paused runtime clock, not a real-time benchmark. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): true Common mistake: Using std::thread::sleep in an async task to implement an asynchronous delay.

Formal Syntax & Structure

rust syntaxrust
tokio::time::sleep(duration).await

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() {    use tokio::time::{sleep, Duration, Instant};    let start = Instant::now();    sleep(Duration::from_secs(2)).await;    println!("{}", start.elapsed() >= Duration::from_secs(2));}
Rust Reference