pub struct TimerWheel<T> { /* private fields */ }Expand description
A hierarchical timing wheel holding payloads of type T. Time is in ticks; the owner
decides what a tick is. See the module docs.
Implementations§
Source§impl<T> TimerWheel<T>
impl<T> TimerWheel<T>
Sourcepub fn new(now: u64) -> TimerWheel<T>
pub fn new(now: u64) -> TimerWheel<T>
An empty wheel whose clock reads now.
Sourcepub fn insert(&mut self, deadline: u64, payload: T) -> TimerId
pub fn insert(&mut self, deadline: u64, payload: T) -> TimerId
Schedules payload to expire at tick deadline (a deadline in the past expires at the
next TimerWheel::advance).
Sourcepub fn is_pending(&self, id: TimerId) -> bool
pub fn is_pending(&self, id: TimerId) -> bool
Whether a timer is still scheduled (not expired and popped, not cancelled).
Sourcepub fn cancel(&mut self, id: TimerId) -> Option<T>
pub fn cancel(&mut self, id: TimerId) -> Option<T>
Cancels a timer and returns its payload, or None if it already expired or was
cancelled.
Sourcepub fn next_deadline(&self) -> Option<u64>
pub fn next_deadline(&self) -> Option<u64>
The earliest tick at which something may need doing: a deadline, or the start of a
slot whose timers must be re-filed. None when the wheel is empty.
Sourcepub fn advance(&mut self, now: u64, out: &mut Vec<T>)
pub fn advance(&mut self, now: u64, out: &mut Vec<T>)
Moves the clock to now and appends every expired payload to out, in deadline order.
Sourcepub fn collect(&mut self, now: u64)
pub fn collect(&mut self, now: u64)
Moves the clock to now and sets every expired timer aside, in deadline order, for
TimerWheel::pop_ready. Until popped they can still be cancelled, so a callback that
cancels a timer due in the same batch stops it from firing.
Sourcepub fn pop_ready(&mut self) -> Option<T>
pub fn pop_ready(&mut self) -> Option<T>
Takes the next expired timer set aside by TimerWheel::collect. Timers inserted after
the collect, even ones already due, wait for the next collect.