DualBitWheel

Struct DualBitWheel 

Source
pub struct DualBitWheel<T, const P_NUM_GEARS: usize = DEFAULT_P_NUM_GEARS, const P_RESOLUTION_MS: u64 = DEFAULT_P_RESOLUTION_MS, const P_SLOT_CAP: usize = DEFAULT_P_SLOT_CAP, const O_NUM_GEARS: usize = DEFAULT_O_NUM_GEARS, const O_RESOLUTION_MS: u64 = DEFAULT_O_RESOLUTION_MS, const O_SLOT_CAP: usize = DEFAULT_O_SLOT_CAP, const O_MAX_PROBES: usize = DEFAULT_O_MAX_PROBES> { /* private fields */ }
Expand description

A dual-lane timer wheel with independent configurations for periodic and one-shot timers.

Periodic wheel: Optimized for bounded, long-duration timers (heartbeats, risk checks).

  • Coarse resolution (100ms default) — precision doesn’t matter for 30s heartbeats
  • Fewer gears (2 default) — covers ~7 minutes, plenty for most periodic needs
  • Full gear probing (64 slots) — always succeeds if under capacity
  • Small slot capacity — bounded population

Oneshot wheel: Optimized for numerous, short-duration timers (order timeouts).

  • Fine resolution (5ms default) — precision matters for tight timeouts
  • More gears (5 default) — covers hours of delay range
  • Limited probing — backpressure signal on overflow
  • Larger slot capacity — handles burst load

Implementations§

Source§

impl<T, const P_NUM_GEARS: usize, const P_RESOLUTION_MS: u64, const P_SLOT_CAP: usize, const O_NUM_GEARS: usize, const O_RESOLUTION_MS: u64, const O_SLOT_CAP: usize, const O_MAX_PROBES: usize> DualBitWheel<T, P_NUM_GEARS, P_RESOLUTION_MS, P_SLOT_CAP, O_NUM_GEARS, O_RESOLUTION_MS, O_SLOT_CAP, O_MAX_PROBES>

Source

pub fn new() -> Self

Source

pub fn with_epoch(epoch: Instant) -> Self

Source

pub fn with_wheels( periodic: BitWheel<T, P_NUM_GEARS, P_RESOLUTION_MS, P_SLOT_CAP, PERIODIC_PROBES>, oneshot: BitWheel<T, O_NUM_GEARS, O_RESOLUTION_MS, O_SLOT_CAP, O_MAX_PROBES>, ) -> Self

Source

pub fn boxed() -> Box<Self>

Source

pub fn boxed_with_epoch(epoch: Instant) -> Box<Self>

Source

pub fn boxed_with_wheels( periodic: BitWheel<T, P_NUM_GEARS, P_RESOLUTION_MS, P_SLOT_CAP, PERIODIC_PROBES>, oneshot: BitWheel<T, O_NUM_GEARS, O_RESOLUTION_MS, O_SLOT_CAP, O_MAX_PROBES>, ) -> Box<Self>

Source

pub const fn periodic_capacity() -> PeriodicCapacityInfo

Capacity info for the periodic wheel.

Source

pub const fn oneshot_capacity() -> OneshotCapacityInfo

Capacity info for the oneshot wheel.

Source

pub fn insert_periodic( &mut self, when: Instant, timer: T, ) -> Result<TimerHandle, InsertError<T>>

Insert a periodic timer (heartbeat, recurring check).

Periodic timers use full gear probing, so insert only fails if the entire wheel is at capacity. This should never happen with proper sizing.

Source

pub fn insert_oneshot( &mut self, when: Instant, timer: T, ) -> Result<TimerHandle, InsertError<T>>

Insert a one-shot timer (order timeout, event deadline).

One-shot timers use limited probing. Insert failure indicates backpressure — the system should throttle new work.

Source

pub fn cancel(&mut self, handle: TimerHandle) -> Option<T>

Cancel a timer by handle.

Returns the timer if it was still pending, None if already fired.

Source

pub fn poll( &mut self, now: Instant, ctx: &mut T::Context, ) -> Result<usize, PollError>
where T: Timer,

Poll both wheels, firing due timers.

Periodic reschedule failures panic in debug (configuration bug). One-shot reschedule failures are counted and returned as PollError.

Source

pub fn is_empty(&self) -> bool

Source

pub fn periodic_is_empty(&self) -> bool

Source

pub fn oneshot_is_empty(&self) -> bool

Source

pub fn duration_until_next(&self) -> Option<Duration>

Source

pub const fn memory_footprint() -> usize

Approximate memory footprint in bytes.

Trait Implementations§

Source§

impl<T, const P_NUM_GEARS: usize, const P_RESOLUTION_MS: u64, const P_SLOT_CAP: usize, const O_NUM_GEARS: usize, const O_RESOLUTION_MS: u64, const O_SLOT_CAP: usize, const O_MAX_PROBES: usize> Default for DualBitWheel<T, P_NUM_GEARS, P_RESOLUTION_MS, P_SLOT_CAP, O_NUM_GEARS, O_RESOLUTION_MS, O_SLOT_CAP, O_MAX_PROBES>

Source§

fn default() -> Self

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

impl<T, const PG: usize, const PR: u64, const PS: usize, const OG: usize, const OR: u64, const OS: usize, const OP: usize> TimerDriver<T> for DualBitWheel<T, PG, PR, PS, OG, OR, OS, OP>
where T: Timer,

Source§

fn insert( &mut self, when: Instant, timer: T, ) -> Result<TimerHandle, InsertError<T>>

Insert a timer to fire at the given instant. Read more
Source§

fn cancel(&mut self, handle: TimerHandle) -> Option<T>

Cancel a pending timer. Read more
Source§

fn poll( &mut self, now: Instant, ctx: &mut T::Context, ) -> Result<usize, PollError>

Poll the wheel, firing all timers due by now. Read more

Auto Trait Implementations§

§

impl<T, const P_NUM_GEARS: usize = DEFAULT_P_NUM_GEARS, const P_RESOLUTION_MS: u64 = DEFAULT_P_RESOLUTION_MS, const P_SLOT_CAP: usize = DEFAULT_P_SLOT_CAP, const O_NUM_GEARS: usize = DEFAULT_O_NUM_GEARS, const O_RESOLUTION_MS: u64 = DEFAULT_O_RESOLUTION_MS, const O_SLOT_CAP: usize = DEFAULT_O_SLOT_CAP, const O_MAX_PROBES: usize = DEFAULT_O_MAX_PROBES> !Freeze for DualBitWheel<T, P_NUM_GEARS, P_RESOLUTION_MS, P_SLOT_CAP, O_NUM_GEARS, O_RESOLUTION_MS, O_SLOT_CAP, O_MAX_PROBES>

§

impl<T, const P_NUM_GEARS: usize = DEFAULT_P_NUM_GEARS, const P_RESOLUTION_MS: u64 = DEFAULT_P_RESOLUTION_MS, const P_SLOT_CAP: usize = DEFAULT_P_SLOT_CAP, const O_NUM_GEARS: usize = DEFAULT_O_NUM_GEARS, const O_RESOLUTION_MS: u64 = DEFAULT_O_RESOLUTION_MS, const O_SLOT_CAP: usize = DEFAULT_O_SLOT_CAP, const O_MAX_PROBES: usize = DEFAULT_O_MAX_PROBES> !RefUnwindSafe for DualBitWheel<T, P_NUM_GEARS, P_RESOLUTION_MS, P_SLOT_CAP, O_NUM_GEARS, O_RESOLUTION_MS, O_SLOT_CAP, O_MAX_PROBES>

§

impl<T, const P_NUM_GEARS: usize, const P_RESOLUTION_MS: u64, const P_SLOT_CAP: usize, const O_NUM_GEARS: usize, const O_RESOLUTION_MS: u64, const O_SLOT_CAP: usize, const O_MAX_PROBES: usize> Send for DualBitWheel<T, P_NUM_GEARS, P_RESOLUTION_MS, P_SLOT_CAP, O_NUM_GEARS, O_RESOLUTION_MS, O_SLOT_CAP, O_MAX_PROBES>
where T: Send,

§

impl<T, const P_NUM_GEARS: usize = DEFAULT_P_NUM_GEARS, const P_RESOLUTION_MS: u64 = DEFAULT_P_RESOLUTION_MS, const P_SLOT_CAP: usize = DEFAULT_P_SLOT_CAP, const O_NUM_GEARS: usize = DEFAULT_O_NUM_GEARS, const O_RESOLUTION_MS: u64 = DEFAULT_O_RESOLUTION_MS, const O_SLOT_CAP: usize = DEFAULT_O_SLOT_CAP, const O_MAX_PROBES: usize = DEFAULT_O_MAX_PROBES> !Sync for DualBitWheel<T, P_NUM_GEARS, P_RESOLUTION_MS, P_SLOT_CAP, O_NUM_GEARS, O_RESOLUTION_MS, O_SLOT_CAP, O_MAX_PROBES>

§

impl<T, const P_NUM_GEARS: usize, const P_RESOLUTION_MS: u64, const P_SLOT_CAP: usize, const O_NUM_GEARS: usize, const O_RESOLUTION_MS: u64, const O_SLOT_CAP: usize, const O_MAX_PROBES: usize> Unpin for DualBitWheel<T, P_NUM_GEARS, P_RESOLUTION_MS, P_SLOT_CAP, O_NUM_GEARS, O_RESOLUTION_MS, O_SLOT_CAP, O_MAX_PROBES>

§

impl<T, const P_NUM_GEARS: usize, const P_RESOLUTION_MS: u64, const P_SLOT_CAP: usize, const O_NUM_GEARS: usize, const O_RESOLUTION_MS: u64, const O_SLOT_CAP: usize, const O_MAX_PROBES: usize> UnwindSafe for DualBitWheel<T, P_NUM_GEARS, P_RESOLUTION_MS, P_SLOT_CAP, O_NUM_GEARS, O_RESOLUTION_MS, O_SLOT_CAP, O_MAX_PROBES>
where T: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.