#binary-heap #priority-queue #timer #tick #time-wheel

timing-wheel

A binary-heap based timing wheel implementation

5 releases

Uses new Rust 2024

0.1.4 Jul 24, 2025
0.1.3 Jul 21, 2025
0.1.2 Jul 13, 2025
0.1.1 Jul 12, 2025
0.1.0 Jul 11, 2025

#9 in #binary-heap

40 downloads per month
Used in 4 crates (via n3io)

MIT license

10KB
140 lines

An improved hash time wheel algorithm based on binary heap priority queue.

Unlike the classic Hashed and Hierarchical Timing Wheels, this library uses a binary heap as a priority queue for timers. During spin, it only needs to compare the timer ticks at the head of the heap to quickly detect expired timers.

Examples

use std::time::{ Duration, Instant };
use timing_wheel::TimeWheel;
use std::thread::sleep;

let mut time_wheel = TimeWheel::new(Duration::from_millis(1));

time_wheel.deadline(Instant::now() + Duration::from_millis(1), ());

sleep(Duration::from_millis(2));

let mut wakers = vec![];

time_wheel.spin(&mut wakers);

assert_eq!(wakers.into_iter().map(|v| v.1).collect::<Vec<_>>(), vec![()]);

timeing-wheel

CI "Crates.io version" "docs.rs docs"

An improved hash time wheel algorithm based on binary heap priority queue.

No runtime deps