[−][src]Trait async_timer::timer::Timer
Timer
Common implementations:
- Windows uses thread pooled timer
- Apple systems uses dispatch source API
- Posix compatible
timer_create
, available on major Posix-compliant systems. Depends on availability ofsiginfo_t::si_value
method. - Wasm uses Web API
SetTimeout
- Dummy timer is used when no implementation is available. Panics when used.
Usage
use async_timer::timer::{Timer, new_timer}; use core::time; use core::pin::Pin; async fn do_something() { let mut work = new_timer(time::Duration::from_secs(2)); assert!(!work.is_ticking()); //Timer starts only on initial poll assert!(!work.is_expired()); Pin::new(&mut work).await; //Remember await consumes future, and we'd prefer to avoid that in order to re-use timer assert!(work.is_expired()); }
Required methods
pub fn new(timeout: Duration) -> Self
[src]
Creates new instance
pub fn is_ticking(&self) -> bool
[src]
Returns whether timer is ongoing.
Note that if it returns false
it doesn't mean that is_expired
will return true
as initially timer may not be armed.
pub fn is_expired(&self) -> bool
[src]
Returns whether timer has expired.
pub fn restart(&mut self, timeout: Duration)
[src]
Restarts timer with new timeout value.
pub fn restart_ctx(&mut self, timeout: Duration, waker: &Waker)
[src]
Restarts timer with new timeout value and waker.
pub fn cancel(&mut self)
[src]
Cancels timer, if it is still ongoing.