timers/
timers.rs

1use native_executor::{
2    spawn,
3    timer::{Timer, sleep},
4};
5use std::time::Duration;
6
7fn main() {
8    spawn(async {
9        println!("Starting timers example");
10
11        // Use the Timer API
12        println!("Waiting for 500ms...");
13        Timer::after(Duration::from_millis(500)).await;
14        println!("500ms elapsed");
15
16        // Use the seconds convenience method
17        println!("Waiting for 1 second...");
18        Timer::after_secs(1).await;
19        println!("1 second elapsed");
20
21        // Use the sleep convenience function
22        println!("Sleeping for 2 seconds...");
23        sleep(2).await;
24        println!("2 seconds elapsed");
25
26        println!("Timers example completed");
27    })
28    .detach();
29
30    // Keep the main thread alive
31    std::thread::sleep(Duration::from_secs(4));
32}