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
impl Timers
Sourcepub fn add_deadline(&mut self, id: Id, deadline: Instant)
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
.
Sourcepub fn add_timeout(&mut self, id: Id, timeout: Duration)
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.
Sourcepub fn remove_deadline(&mut self, id: Id)
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§
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> 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
Mutably borrows from an owned value. Read more