smol/examples/timer-sleep.rs

18 lines
351 B
Rust
Raw Normal View History

2020-04-21 15:51:07 +00:00
// TODO: document
2020-02-05 18:56:07 +00:00
use std::time::{Duration, Instant};
2020-02-09 14:32:44 +00:00
use smol::Timer;
2020-02-05 18:56:07 +00:00
2020-03-29 15:59:28 +00:00
async fn sleep(dur: Duration) {
Timer::after(dur).await;
}
2020-02-05 18:56:07 +00:00
fn main() {
2020-02-09 14:32:44 +00:00
smol::run(async {
2020-02-07 10:54:45 +00:00
let start = Instant::now();
2020-03-31 16:04:16 +00:00
println!("Sleeping...");
2020-03-29 15:59:28 +00:00
sleep(Duration::from_secs(1)).await;
2020-03-31 16:04:16 +00:00
println!("Woke up after {:?}", start.elapsed());
2020-02-05 18:56:07 +00:00
})
}