#timer #native #schedule #linux-macos

native-timer

Timer library which uses OS timer capabilities

10 releases (4 breaking)

0.5.2 Jan 22, 2023
0.5.1 Jan 22, 2023
0.4.0 Jan 21, 2023
0.3.3 Jan 20, 2023
0.1.0 Jan 15, 2023

#646 in Concurrency

Download history 86/week @ 2024-07-28 13/week @ 2024-08-04 9/week @ 2024-08-11 13/week @ 2024-08-18 7/week @ 2024-08-25 30/week @ 2024-09-01 10/week @ 2024-09-08 52/week @ 2024-09-22 7/week @ 2024-09-29 16/week @ 2024-10-06 49/week @ 2024-10-13 56/week @ 2024-10-20 164/week @ 2024-10-27 29/week @ 2024-11-03

299 downloads per month

MIT license

34KB
607 lines

Native Timer for Rust

Provide a timer functionality which uses OS capabilities. Currently supports Windows, Linux, and MacOS.

Currently, only both Windows and Linux platforms are supported.

Features

  • tracker (default) - Enable static callback tracker. It should minimize the native callback into an invalid timer context, that has been recently destroyed.

Examples

To fire an one-shot task:

# use std::sync::{Arc, atomic::{AtomicBool, Ordering}};
# use std::thread;
# use std::time::Duration;
use native_timer::fire_oneshot;

let flag = Arc::new(AtomicBool::new(false));
let shared_flag = flag.clone();
fire_oneshot(Duration::from_millis(100), None, move || {
    let _ = &shared_flag.store(true, Ordering::SeqCst);
}).unwrap();
thread::sleep(Duration::from_millis(200));
assert!(flag.load(Ordering::SeqCst));

For more usages, see /src/examples/simple.rs.

Credit

Linux and MacOS implementations are recovered from Autd3 open source library on tag v1.10.0, which is before being removed by commits afterwards.

Dependencies

~0.4–39MB
~535K SLoC