Crate simple_delay_queue

Source
Expand description

A crate providing a TimeQueue that delays yielding inserted elements until a fixed timeout has elapsed. Each inserted element is stored together with its expiration time (current Tokio Instant plus the constant timeout). Since the timeout is constant, the elements naturally expire in FIFO order, and both push and pop operations are O(1).

§Differences with tokio::time::DelayQueue

The TimeQueue in this crate is designed to be simpler and faster than tokio::time::DelayQueue. While DelayQueue offers more features such as the ability to reset timeouts and remove elements before they expire, TimeQueue focuses on providing a minimalistic and efficient implementation for cases where these additional features are not needed.

Key differences:

  • Fixed Timeout: TimeQueue uses a constant timeout for all elements, whereas DelayQueue allows specifying different timeouts for each element.
  • FIFO Order: Elements in TimeQueue expire in the order they were inserted, ensuring FIFO order. DelayQueue does not guarantee FIFO order if elements have different timeouts.
  • Performance: TimeQueue is optimized for performance with O(1) push and pop operations, making it faster for use cases where the additional features of DelayQueue are not required.

Structs§

TimeQueue
A time queue that delays yielding inserted elements until a fixed timeout has elapsed. Each inserted element is stored together with its expiration time (current Tokio Instant plus the constant timeout). Since the timeout is constant, the elements naturally expire in FIFO order, and both push and pop operations are O(1).