pub struct Timer { /* private fields */ }
Implementations§
source§impl Timer
impl Timer
sourcepub fn new<F: 'static + Fn(&Host) + Send + Sync>(on_expire: F) -> Self
pub fn new<F: 'static + Fn(&Host) + Send + Sync>(on_expire: F) -> Self
Create a new Timer that directly executes on_expire
on
expiration. on_expire
will cause a panic if it calls mutable methods
of the enclosing Timer. If it may need to call mutable methods of the
Timer, it should push a new task to the scheduler to do so.
sourcepub fn expiration_count(&self) -> u64
pub fn expiration_count(&self) -> u64
Returns the number of timer expirations that have occurred since the last time
Timer::consume_expiration_count()
was called without resetting the counter.
sourcepub fn expire_interval(&self) -> Option<SimulationTime>
pub fn expire_interval(&self) -> Option<SimulationTime>
Returns the currently configured timer expiration interval if this timer is configured to periodically expire, or None if the timer is configured for a one-shot expiration.
sourcepub fn consume_expiration_count(&mut self) -> u64
pub fn consume_expiration_count(&mut self) -> u64
Returns the number of timer expirations that have occurred since the last time
Timer::consume_expiration_count()
was called and resets the counter to zero.
sourcepub fn remaining_time(&self) -> Option<SimulationTime>
pub fn remaining_time(&self) -> Option<SimulationTime>
Returns the remaining time until the next expiration if the timer is armed, or None otherwise.
sourcepub fn disarm(&mut self)
pub fn disarm(&mut self)
Deactivate the timer so that it does not issue on_expire()
callback notifications.
sourcepub fn arm(
&mut self,
host: &Host,
expire_time: EmulatedTime,
expire_interval: Option<SimulationTime>,
)
pub fn arm( &mut self, host: &Host, expire_time: EmulatedTime, expire_interval: Option<SimulationTime>, )
Activate the timer so that it starts issuing on_expire()
callback notifications.
The expire_time
instant specifies the next time that the timer will expire and issue an
on_expire()
notification callback. The expire_interval
duration is optional: if Some
,
it configures the timer in periodic mode where it issues on_expire()
notification
callbacks every interval of time; if None
, the timer is configured in one-shot mode and
will become disarmed after the first expiration.
Panics if expire_time
is in the past or if expire_interval
is Some
but not positive.
Auto Trait Implementations§
impl Freeze for Timer
impl !RefUnwindSafe for Timer
impl Send for Timer
impl Sync for Timer
impl Unpin for Timer
impl !UnwindSafe for Timer
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more