pub struct Timer { /* private fields */ }
Expand description
Posix timer wrapper
Implementations
sourceimpl Timer
impl Timer
sourcepub const unsafe fn uninit() -> Self
pub const unsafe fn uninit() -> Self
Creates new uninitialized instance.
In order to use it one must call init
.
sourcepub fn init(&self, cb: Callback) -> bool
pub fn init(&self, cb: Callback) -> bool
Performs timer initialization
cb
pointer to function to invoke when timer expires.
Returns whether timer has been initialized successfully or not.
If timer is already initialized does nothing, returning false.
sourcepub fn new(cb: Callback) -> Option<Self>
pub fn new(cb: Callback) -> Option<Self>
Creates new timer, invoking provided cb
when timer expires.
On failure, returns None
sourcepub fn schedule_interval(&self, timeout: Duration, interval: Duration) -> bool
pub fn schedule_interval(&self, timeout: Duration, interval: Duration) -> bool
Schedules timer to alarm periodically with interval
with initial alarm of timeout
.
Note that if timer has been scheduled before, but hasn’t expire yet, behaviour is undefined (Callback may or may not be called).
To prevent that user must cancel
timer first.
Returns true
if successfully set, otherwise on error returns false
sourcepub fn is_scheduled(&self) -> bool
pub fn is_scheduled(&self) -> bool
Returns true
if timer has been scheduled and still pending.
On Win/Mac it only returns whether timer has been scheduled, as there is no way to check whether timer is ongoing
sourceimpl Timer
impl Timer
sourcepub fn schedule_once(&self, timeout: Duration) -> bool
pub fn schedule_once(&self, timeout: Duration) -> bool
Schedules timer to alarm once after timeout
passes.
Note that if timer has been scheduled before, but hasn’t expire yet, it shall be cancelled.
To prevent that user must cancel
timer first.
Returns true
if successfully set, otherwise on error returns false