Debian Codegraph @

examples/high_precision.rs

raw symbols SCIP
1 use std::time::{Duration, Instant};
2
3 use calloop::{
4 timer::{TimeoutAction, Timer},
5 EventLoop,
6 };
7
8 fn main() {
9 let mut event_loop =
10 EventLoop::try_new_high_precision().expect("Failed to initialize the event loop!");
11
12 let before = Instant::now();
13
14 event_loop
15 .handle()
16 .insert_source(
17 Timer::from_duration(Duration::from_micros(20)),
18 |_, _, _| TimeoutAction::Drop,
19 )
20 .unwrap();
21
22 event_loop.dispatch(None, &mut ()).unwrap();
23
24 let elapsed = before.elapsed();
25
26 println!(
27 "The event loop slept for {} microseconds.",
28 elapsed.as_micros()
29 );
30 }