expression
Sleep until an absolute Tokio deadline
Compute a target using Tokio Instant, then wait for it. Keep the original target when earlier work consumes part of a total delay. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): true Common mistake: Starting a fresh five-second delay after the first two seconds of work.
Formal Syntax & Structure
rust syntaxrust
tokio::time::sleep_until(deadline).awaitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() { use tokio::time::{sleep, sleep_until, Duration, Instant}; let deadline = Instant::now() + Duration::from_secs(5); sleep(Duration::from_secs(2)).await; sleep_until(deadline).await; println!("{}", Instant::now() >= deadline);}