Crates.io | native-timer |
lib.rs | native-timer |
version | 0.5.2 |
source | src |
created_at | 2023-01-15 11:31:03.558979 |
updated_at | 2023-01-22 15:10:16.889375 |
description | Timer library which uses OS timer capabilities. |
homepage | https://docs.rs/native-timer |
repository | https://github.com/ruxo/native-timer |
max_upload_size | |
id | 759401 |
size | 44,764 |
Provide a timer functionality which uses OS capabilities. Currently supports Windows, Linux, and MacOS.
Currently, only both Windows and Linux platforms are supported.
tracker
(default) - Enable static callback tracker. It should minimize the native callback into an invalid timer
context, that has been recently destroyed.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
.
Linux and MacOS implementations are recovered from Autd3 open source library
on tag v1.10.0
, which is before being removed by commits afterwards.