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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! `tokio-osinterval` provides [`OsInterval`], an alternative to
//! [`tokio::time::Interval`] that drives its periodic ticks from the
//! operating system's native async-capable timer facility instead of
//! tokio's userspace timer wheel.
//!
//! Backends:
//!
//! | Platform | Backend |
//! |----------------------------------|------------------------------------------|
//! | Linux / Android | `timerfd_create(CLOCK_MONOTONIC, …)` |
//! | macOS / iOS / *BSD | `kqueue` + `EVFILT_TIMER` |
//! | Windows | `CreateThreadpoolTimer` |
//! | Other / `--no-default-features` | `tokio::time::sleep_until` fallback |
//!
//! The public API mirrors [`tokio::time::Interval`] closely so swapping
//! is mostly an import change.
//!
//! # Example
//!
//! ```no_run
//! use std::time::Duration;
//! use tokio_osinterval::interval;
//!
//! # async fn run() {
//! let mut ticker = interval(Duration::from_millis(100));
//! for _ in 0..5 {
//! ticker.tick().await;
//! // do periodic work
//! }
//! # }
//! ```
//!
//! # Differences from [`tokio::time::Interval`]
//!
//! * Each `OsInterval` owns one kernel timer object (an fd or
//! `PTP_TIMER`); creating it requires an active tokio runtime.
//! * The native backends bypass `tokio::time::pause()` — for tests that
//! need a paused clock, build with `default-features = false`.
//! * Sub-millisecond periods are honored on platforms whose timers
//! support them (kqueue with `NOTE_NSECONDS`, timerfd, Windows
//! high-resolution timers).
//!
//! # Cargo features
//!
//! * **`interval`** *(default)* — enables [`OsInterval`] and the
//! `interval` / `interval_at` constructors.
//! * **`os-native`** *(default)* — selects the platform-native backend
//! for `OsInterval`. Disable to force the portable
//! `tokio::time::sleep_until` fallback. Has no effect unless
//! `interval` is also enabled.
//! * **`periodic`** — enables [`PeriodicInterval`], a stripped-down
//! ticker driven by a single kernel-side periodic timer (Linux/BSD
//! only).
//!
//! `interval` and `periodic` are independent: enable either, both, or
//! (with `default-features = false`) neither.
pub use ;
pub use ;