A simple async Delay Queue
A lightweight and efficient time-based queue implementation for Tokio that delays yielding inserted elements until a fixed timeout has elapsed.
Overview
TimeQueue provides a simple, performant queue that yields elements in FIFO order after a fixed timeout has elapsed. Unlike more complex delay queues, TimeQueue focuses on efficiency with O(1) push and pop operations by enforcing a constant timeout for all elements.
Features
- Fixed Timeout: Uses a constant timeout for all elements, optimizing for simplicity and performance
- FIFO Order: Elements expire in the exact order they were inserted
- O(1) Operations: Both push and pop operations are constant time
- Tokio Integration: Seamlessly works with Tokio's async runtime
- Stream Implementation: Can be used with Rust's async stream combinators
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["full"] }
Usage
use Duration;
use TimeQueue;
use StreamExt;
async
When to Use TimeQueue
TimeQueue is ideal for:
- Rate limiting
- Implementing simple delays
- Processing items in order after a fixed cooldown period
- Any scenario where all items should be delayed by the same amount of time
Comparison with tokio::time::DelayQueue
TimeQueue is designed to be simpler and faster than tokio::time::DelayQueue for specific use cases:
| Feature | TimeQueue | DelayQueue |
|---|---|---|
| Timeout Configuration | Fixed for all elements | Configurable per element |
| Order Guarantee | FIFO | Based on expiration time |
| Performance | O(1) push/pop | O(log n) |
| Reset Timeouts | No | Yes |
| Remove Elements | No | Yes |
| Use Case | Simple, efficient delay queue | Feature-rich priority queue |