futures

需要单独的包 futures_timer

  1. use std::time::Duration;
  2. use futures_timer::Delay;
  3. let now = Delay::new(Duration::from_secs(3)).await;
  4. println!("waited for 3 secs");

async-std

  1. use async_std::task;
  2. use std::time::Duration;
  3. task::sleep(time::Duration::from_secs(1)).await;

smol

  1. use smol::Timer;
  2. use std::time::Duration;
  3. Timer::after(Duration::from_secs(1)).await;