wheeltimer
A high-performance asynchronous time wheel-based timer implementation in Rust, inspired by Netty's HashedWheelTimer.
This crate provides a scalable and thread-safe way to schedule delayed tasks using the time wheel algorithm, ideal for use cases such as connection timeouts, heartbeat checks, or any system requiring large numbers of scheduled events.
โจ Features
- โฑ๏ธ Asynchronous task scheduling with configurable tick duration
- ๐งฎ Efficient time wheel structure (power-of-two sized buckets)
- ๐งต Thread-safe design using
Arc,RwLock, andMutex - ๐ซ Support for cancelling pending timeouts
- ๐ Configurable maximum number of pending timeouts
- ๐ฆ Easy-to-use API with support for async closures
๐ฆ Usage
Add this to your Cargo.toml
[]
= "0.1"
๐ง Example
use WheelTimer;
use Duration;
async
๐ ๏ธ API Overview
WheelTimer::new(tick_duration, ticks_per_wheel, max_pending_timeouts)โ Creates a new timer..start()โ Starts the internal worker thread..new_timeout(delay, task)โ Schedules a task to run after a delay..stop()โ Stops the timer and cancels all pending timeouts..cancel()onTimeoutโ Cancels an individual timeout before it fires.
๐ Documentation
You can view the full documentation online:
๐ https://docs.rs/wheeltimer
Or build it locally:
๐งช Testing
Run tests:
๐ค Contributing
Contributions are welcome! Feel free to open issues or submit pull requests on GitHub.
๐ License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)