1use std::thread::sleep;
2use std::time::Duration;
3use native_timer::{CallbackHint, schedule_interval, schedule_oneshot};
4
5fn main() {
6 let t1 = schedule_interval(Duration::from_secs(1), None, || println!("Tick!")).unwrap();
7 let t2 = schedule_interval(Duration::from_secs(1), Some(CallbackHint::QuickFunction), || println!("Tick fast!")).unwrap();
8 let t3 = schedule_oneshot(Duration::from_millis(800), Some(CallbackHint::QuickFunction), || println!("One shot!")).unwrap();
9
10 let mut lazy_count = 0;
11 let t4 = schedule_interval(Duration::from_secs(1), Some(CallbackHint::SlowFunction(Duration::from_secs(5))), || {
12 lazy_count += 1;
13 let my_id = lazy_count;
14 println!("I'm lazy... #{my_id}");
15 sleep(Duration::from_secs(3));
16 println!("#{my_id} I may have been called with a dedicated thread");
17 }).unwrap();
18
19 println!("Wait for timer working");
20 sleep(Duration::from_secs(5));
21
22 println!("Dropping timers");
23
24 drop(t1);
26 drop(t2);
27 drop(t3);
28 drop(t4);
29
30 println!("That's it!");
31}