[][src]Struct gaea::Timers

pub struct Timers { /* fields omitted */ }

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)));

Methods

impl Timers[src]

pub fn new() -> Timers[src]

Create a new time event source.

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

Add a new deadline.

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

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

Add a new timeout.

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

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

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

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

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

A blocking poll for readiness events. Read more

impl Default for Timers[src]

impl Debug for Timers[src]

Auto Trait Implementations

impl Send for Timers

impl Sync for Timers

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]