#![allow(non_snake_case)] use std::sync::Arc; use std::thread; use std::time::{Duration, Instant}; use tokio::sync::Notify; async fn delay(dur: Duration) { let when = Instant::now() + dur; let notify = Arc::new(Notify::new()); let notify2 = notify.clone(); thread::spawn(move || { let now = Instant::now(); if now < when { thread::sleep(when - now); } notify2.notify_one(); }); notify.notified().await; }