Struct Timers

Source
pub struct Timers { /* private fields */ }
Expand description

Timer readiness queue.

Polling this event source never returns an error.

§Examples

use std::time::Instant;

use gaea::{Event, Timers, Ready, event, poll};

let mut timers = Timers::new();
let mut events = Vec::new();

// Add a deadline, to trigger an event immediately.
let id = event::Id(0);
timers.add_deadline(id, Instant::now());

// Now we poll for events. Note that this is safe to unwrap as polling
// `Timers` never returns an error.
poll::<_, ()>(&mut [&mut timers], &mut events, None).unwrap();

assert_eq!(events.get(0), Some(&Event::new(id, Ready::TIMER)));

Implementations§

Source§

impl Timers

Source

pub fn new() -> Timers

Create a new time event source.

Source

pub fn add_deadline(&mut self, id: Id, deadline: Instant)

Add a new deadline.

This will cause an event to trigger after the deadline has passed with the Ready::TIMER readiness and provided id.

Source

pub fn add_timeout(&mut self, id: Id, timeout: Duration)

Add a new timeout.

This is the same as add_deadline, but then using a Duration, see add_deadline for more information.

Source

pub fn remove_deadline(&mut self, id: Id)

Remove a previously added deadline.

§Notes

Removing a deadline is a costly operation. For better performance it is advised to not bother with removing and instead ignore the event when it comes up.

Trait Implementations§

Source§

impl Debug for Timers

Source§

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

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

impl Default for Timers

Source§

fn default() -> Timers

Returns the “default value” for a type. Read more
Source§

impl<ES, E> Source<ES, E> for Timers
where ES: Sink,

Source§

fn max_timeout(&self) -> Option<Duration>

The duration until the next event will be available. Read more
Source§

fn poll(&mut self, event_sink: &mut ES) -> Result<(), E>

Poll for readiness events. Read more
Source§

fn blocking_poll( &mut self, event_sink: &mut ES, timeout: Option<Duration>, ) -> Result<(), E>

A blocking poll for readiness events. Read more

Auto Trait Implementations§

§

impl Freeze for Timers

§

impl RefUnwindSafe for Timers

§

impl Send for Timers

§

impl Sync for Timers

§

impl Unpin for Timers

§

impl UnwindSafe for Timers

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.