File: high_precision.rs

package info (click to toggle)
rust-calloop 0.13.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 596 kB
  • sloc: makefile: 2
file content (30 lines) | stat: -rw-r--r-- 723 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::time::{Duration, Instant};

use calloop::{
    timer::{TimeoutAction, Timer},
    EventLoop,
};

fn main() {
    // As of calloop v0.11 there is no difference between low and high precision event loops.
    let mut event_loop = EventLoop::try_new().expect("Failed to initialize the event loop!");

    let before = Instant::now();

    event_loop
        .handle()
        .insert_source(
            Timer::from_duration(Duration::from_micros(20)),
            |_, _, _| TimeoutAction::Drop,
        )
        .unwrap();

    event_loop.dispatch(None, &mut ()).unwrap();

    let elapsed = before.elapsed();

    println!(
        "The event loop slept for {} microseconds.",
        elapsed.as_micros()
    );
}