Skip to main content

TimerWheel

Struct TimerWheel 

Source
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>

Source

pub fn new(now: u64) -> TimerWheel<T>

An empty wheel whose clock reads now.

Source

pub fn now(&self) -> u64

The wheel’s current tick.

Source

pub fn len(&self) -> usize

Scheduled timers.

Source

pub fn is_empty(&self) -> bool

Whether no timer is scheduled.

Source

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

Source

pub fn is_pending(&self, id: TimerId) -> bool

Whether a timer is still scheduled (not expired and popped, not cancelled).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T> Debug for TimerWheel<T>

Source§

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

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

impl<T> Default for TimerWheel<T>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Forget for TimerWheel<T>

§

impl<T> Freeze for TimerWheel<T>
where Vec<Node<T>>: Freeze,

§

impl<T> Move for TimerWheel<T>

§

impl<T> RefUnwindSafe for TimerWheel<T>
where Vec<Node<T>>: RefUnwindSafe,

§

impl<T> Send for TimerWheel<T>
where Vec<Node<T>>: Send,

§

impl<T> Sync for TimerWheel<T>
where Vec<Node<T>>: Sync,

§

impl<T> Unpin for TimerWheel<T>
where Vec<Node<T>>: Unpin,

§

impl<T> UnsafeUnpin for TimerWheel<T>
where Vec<Node<T>>: UnsafeUnpin,

§

impl<T> UnwindSafe for TimerWheel<T>
where Vec<Node<T>>: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.