pub struct Timer { /* private fields */ }
Expand description
A timer event source
When registered to the event loop, it will trigger an event once its deadline is reached.
If the deadline is in the past relative to the moment of its insertion in the event loop,
the TImer
will trigger an event as soon as the event loop is dispatched.
Implementations§
source§impl Timer
impl Timer
sourcepub fn immediate() -> Timer
pub fn immediate() -> Timer
Create a timer that will fire immediately when inserted in the event loop
sourcepub fn from_duration(duration: Duration) -> Timer
pub fn from_duration(duration: Duration) -> Timer
Create a timer that will fire after a given duration from now
sourcepub fn from_deadline(deadline: Instant) -> Timer
pub fn from_deadline(deadline: Instant) -> Timer
Create a timer that will fire at a given instant
sourcepub fn set_deadline(&mut self, deadline: Instant)
pub fn set_deadline(&mut self, deadline: Instant)
Changes the deadline of this timer to an Instant
If the Timer
is currently registered in the event loop, it needs to be
re-registered for this change to take effect.
sourcepub fn set_duration(&mut self, duration: Duration)
pub fn set_duration(&mut self, duration: Duration)
Changes the deadline of this timer to a Duration
from now
If the Timer
is currently registered in the event loop, it needs to be
re-registered for this change to take effect.
sourcepub fn current_deadline(&self) -> Option<Instant>
pub fn current_deadline(&self) -> Option<Instant>
Get the current deadline of this Timer
Returns None
if the timer has overflowed.
Trait Implementations§
source§impl EventSource for Timer
impl EventSource for Timer
§type Ret = TimeoutAction
type Ret = TimeoutAction
§type Error = Error
type Error = Error
process_events()
(not the user callback!).source§fn process_events<F>(
&mut self,
_: Readiness,
token: Token,
callback: F
) -> Result<PostAction, Self::Error>
fn process_events<F>( &mut self, _: Readiness, token: Token, callback: F ) -> Result<PostAction, Self::Error>
source§fn register(
&mut self,
poll: &mut Poll,
token_factory: &mut TokenFactory
) -> Result<()>
fn register( &mut self, poll: &mut Poll, token_factory: &mut TokenFactory ) -> Result<()>
source§fn reregister(
&mut self,
poll: &mut Poll,
token_factory: &mut TokenFactory
) -> Result<()>
fn reregister( &mut self, poll: &mut Poll, token_factory: &mut TokenFactory ) -> Result<()>
source§fn unregister(&mut self, poll: &mut Poll) -> Result<()>
fn unregister(&mut self, poll: &mut Poll) -> Result<()>
source§const NEEDS_EXTRA_LIFECYCLE_EVENTS: bool = false
const NEEDS_EXTRA_LIFECYCLE_EVENTS: bool = false
EventSource::before_sleep
and EventSource::before_handle_events
notifications. These are opt-in because
they require more expensive checks, and almost all sources will not need these notificationssource§fn before_sleep(&mut self) -> Result<Option<(Readiness, Token)>>
fn before_sleep(&mut self) -> Result<Option<(Readiness, Token)>>
poll
is about to begin Read moresource§fn before_handle_events(&mut self, events: EventIterator<'_>)
fn before_handle_events(&mut self, events: EventIterator<'_>)
EventSource::process_events
will
be called with the given events for this source. The iterator may be empty,
which indicates that no events were generated for this source Read more