periodic_timer 0.1.1

simple Rust implementation of periodic timer.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use periodic_timer::Timer;
use std::sync::atomic::{AtomicU64, Ordering};

fn main() {
    let time = std::time::Instant::now();
    let prev = AtomicU64::new(time.elapsed().as_micros() as u64);
    let timer = Timer::new(0.1, move || {
        let time = time.elapsed().as_micros() as u64;

        println!("interval: {} us", time - prev.load(Ordering::SeqCst));
        prev.store(time, Ordering::SeqCst);
    });

    timer.start();

    loop {}
}