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>
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>
pub fn new() -> Self
pub fn with_epoch(epoch: Instant) -> Self
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
pub fn boxed() -> Box<Self>
pub fn boxed_with_epoch(epoch: Instant) -> Box<Self>
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>
Sourcepub const fn periodic_capacity() -> PeriodicCapacityInfo
pub const fn periodic_capacity() -> PeriodicCapacityInfo
Capacity info for the periodic wheel.
Sourcepub const fn oneshot_capacity() -> OneshotCapacityInfo
pub const fn oneshot_capacity() -> OneshotCapacityInfo
Capacity info for the oneshot wheel.
Sourcepub fn insert_periodic(
&mut self,
when: Instant,
timer: T,
) -> Result<TimerHandle, InsertError<T>>
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.
Sourcepub fn insert_oneshot(
&mut self,
when: Instant,
timer: T,
) -> Result<TimerHandle, InsertError<T>>
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.
Sourcepub fn cancel(&mut self, handle: TimerHandle) -> Option<T>
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.
Sourcepub fn poll(
&mut self,
now: Instant,
ctx: &mut T::Context,
) -> Result<usize, PollError>where
T: Timer,
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.
pub fn is_empty(&self) -> bool
pub fn periodic_is_empty(&self) -> bool
pub fn oneshot_is_empty(&self) -> bool
pub fn duration_until_next(&self) -> Option<Duration>
Sourcepub const fn memory_footprint() -> usize
pub const fn memory_footprint() -> usize
Approximate memory footprint in bytes.