Crate native_timer

Source
Expand description

§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 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.

Structs§

Timer
Represents an instance of scheduled timer for a specific task.
TimerQueue
TimerQueue manages scheduling of timers. Timer can be created from TimerQueue only.

Enums§

CallbackHint
Scheduler hint about the callback function.
TimerError

Constants§

DEFAULT_ACCEPTABLE_EXECUTION_TIME

Functions§

fire_oneshot
Schedule an one-shot background task on the default TimerQueue. Note that, unlike other schedule_* functions, this fire_oneshot requires a 'static lifetime closure.
schedule_interval
Schedule an interval task on the default TimerQueue.
schedule_oneshot
Schedule an one-shot task on the default TimerQueue.

Type Aliases§

Result