Expand description
High-performance timer wheel with O(1) insert and cancel.
nexus-timer provides a hierarchical timer wheel inspired by the Linux
kernel’s timer infrastructure (Gleixner 2016). Timers are placed into
coarser slots at higher levels — no cascading, no entry movement after
insertion.
§Design
- No cascade: Once placed, an entry never moves. Poll checks each entry’s exact deadline. This eliminates the latency spikes that cascading timer wheels exhibit.
- Intrusive active-slot lists: Only non-empty slots are visited during poll and next-deadline queries. No bitmap, no full scan.
- Embedded refcounting: Lightweight
Cell<u8>refcount per entry enables fire-and-forget timers alongside cancellable timers without external reference-counting machinery. - Generic storage: Parameterized over slab backend — bounded (fixed-capacity) or unbounded (growable).
§Quick Start
use std::time::{Duration, Instant};
use nexus_timer::Wheel;
let now = Instant::now();
let mut wheel: Wheel<u64> = Wheel::unbounded(4096, now);
// Schedule a timer 100ms from now
let handle = wheel.schedule(now + Duration::from_millis(100), 42u64);
// Cancel before it fires — get the value back
let value = wheel.cancel(handle);
assert_eq!(value, Some(42));Modules§
- store
- Slab storage traits for instance-based (non-ZST) slabs.
Structs§
- Bounded
Wheel Builder - Terminal builder for a bounded timer wheel.
- Full
- Error returned when a bounded allocator is full.
- Timer
Handle - Handle to a scheduled timer.
- Timer
Wheel - A multi-level, no-cascade timer wheel.
- Unbounded
Wheel Builder - Terminal builder for an unbounded timer wheel.
- Wheel
Builder - Builder for configuring a timer wheel.
- Wheel
Entry - Timer wheel entry stored inside a slab slot.
Type Aliases§
- Bounded
Wheel - A timer wheel backed by a fixed-capacity slab.
- Wheel
- A timer wheel backed by a growable slab.