Crate timing_wheel

Source
Expand description

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![()]);

Structs§

TimeWheel
A binary-heap based timing wheel implementation.