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:
TimeQueueuses a constant timeout for all elements, whereasDelayQueueallows specifying different timeouts for each element. - FIFO Order: Elements in
TimeQueueexpire in the order they were inserted, ensuring FIFO order.DelayQueuedoes not guarantee FIFO order if elements have different timeouts. - Performance:
TimeQueueis optimized for performance with O(1) push and pop operations, making it faster for use cases where the additional features ofDelayQueueare not required.
Structs§
- Time
Queue - 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).