Struct calloop::sources::timer::Timer

source ·
pub struct Timer {
    registration: Option<Registration>,
    deadline: Instant,
}
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.

Fields§

§registration: Option<Registration>§deadline: Instant

Implementations§

source§

impl Timer

source

pub fn immediate() -> Timer

Create a timer that will fire immediately when inserted in the event loop

source

pub fn from_duration(duration: Duration) -> Timer

Create a timer that will fire after a given duration from now

source

pub fn from_deadline(deadline: Instant) -> Timer

Create a timer that will fire at a given instant

source

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.

source

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.

source

pub fn current_deadline(&self) -> Instant

Get the current deadline of this Timer

Trait Implementations§

source§

impl Debug for Timer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl EventSource for Timer

§

type Event = Instant

The type of events generated by your source.
§

type Metadata = ()

Some metadata of your event source Read more
§

type Ret = TimeoutAction

The return type of the user callback Read more
§

type Error = Error

The error type returned from process_events() (not the user callback!).
source§

fn process_events<F>( &mut self, _: Readiness, token: Token, callback: F ) -> Result<PostAction, Self::Error>where F: FnMut(Self::Event, &mut Self::Metadata) -> Self::Ret,

Process any relevant events Read more
source§

fn register( &mut self, poll: &mut Poll, token_factory: &mut TokenFactory ) -> Result<()>

Register yourself to this poll instance Read more
source§

fn reregister( &mut self, poll: &mut Poll, token_factory: &mut TokenFactory ) -> Result<()>

Re-register your file descriptors Read more
source§

fn unregister(&mut self, poll: &mut Poll) -> Result<()>

Unregister your file descriptors Read more
source§

fn pre_run<F>(&mut self, _callback: F) -> Result<()>where F: FnMut(Self::Event, &mut Self::Metadata) -> Self::Ret,

Notification that a polling session is going to start Read more
source§

fn post_run<F>(&mut self, _callback: F) -> Result<()>where F: FnMut(Self::Event, &mut Self::Metadata) -> Self::Ret,

Notification that the current polling session ended Read more

Auto Trait Implementations§

§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.