async_timer/oneshot/
mod.rs1use core::{task, time};
4use core::marker::Unpin;
5use core::future::Future;
6
7pub trait Oneshot: Send + Sync + Unpin + Future<Output=()> {
44 fn new(timeout: time::Duration) -> Self;
48
49 fn is_ticking(&self) -> bool;
54
55 fn is_expired(&self) -> bool;
57
58 fn cancel(&mut self);
60
61 fn restart(&mut self, timeout: time::Duration, waker: &task::Waker);
65}
66
67mod state;
68
69#[cfg(target_arch = "wasm32")]
70pub mod web;
71#[cfg(windows)]
72pub mod win;
73#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))]
74pub mod posix;
75#[cfg(any(target_os = "macos", target_os = "ios"))]
76pub mod apple;
77#[cfg(all(feature = "tokio_on", any(target_os = "linux", target_os = "android")))]
78pub mod timer_fd;
79#[cfg(all(feature = "tokio_on", any(target_os = "bitrig", target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd")))]
80pub mod kqueue;
81pub mod dummy;
82mod extra;
83
84pub use extra::NeverTimer;
85
86#[cfg(all(feature = "tokio_on", any(target_os = "linux", target_os = "android")))]
87pub use timer_fd::TimerFd;
88
89#[cfg(target_arch = "wasm32")]
90pub type Timer = web::WebTimer;
92
93#[cfg(windows)]
94pub type Timer = win::WinTimer;
96
97#[cfg(all(not(feature = "tokio_on"), not(any(target_os = "macos", target_os = "ios")), unix))]
98pub type Timer = posix::PosixTimer;
100#[cfg(all(feature = "tokio_on", any(target_os = "linux", target_os = "android")))]
101pub type Timer = timer_fd::TimerFd;
103
104#[cfg(all(not(feature = "tokio_on"), any(target_os = "macos", target_os = "ios")))]
105pub type Timer = apple::AppleTimer;
107#[cfg(all(feature = "tokio_on", any(target_os = "bitrig", target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd")))]
108pub type Timer = kqueue::KqueueTimer;
110
111#[cfg(not(any(
112windows, target_arch = "wasm32", unix,
113all(feature = "tokio_on", any(target_os = "bitrig", target_os = "ios", target_os = "macos"))
114)))]
115pub type Timer = dummy::DummyTimer;