wheeltimer 0.1.0

wheelTimer is Netty's HashedWheelTimer implementation based on Rust
Documentation
# 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`, and `Mutex`
- ๐Ÿšซ 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

```toml
[dependencies]
wheeltimer = "0.1"
```


### ๐Ÿ”ง Example

```rust
use wheeltimer::WheelTimer;
use std::time::Duration;

#[tokio::main]
async fn main() {
    // Create a new timer with 10ms tick duration and 1024 buckets
    let timer = WheelTimer::new(Duration::from_millis(10), 1024, 100000).unwrap();

    // Start the timer
    timer.start().await;

    // Schedule a timeout after 2 seconds
    let timeout = timer.new_timeout(Duration::from_secs(2), |timeout| {
        async move {
            println!("A delayed task is executed!");
        }
    }).await.unwrap();

    // Wait for the task to execute
    tokio::time::sleep(Duration::from_secs(3)).await;

    // Stop the timer
    timer.stop().await;
}
```


## ๐Ÿ› ๏ธ 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()` on `Timeout` โ€“ Cancels an individual timeout before it fires.

## ๐Ÿ“ Documentation

You can view the full documentation online:

[๐Ÿ“š https://docs.rs/wheeltimer](https://docs.rs/wheeltimer)

Or build it locally:

```bash
cargo doc --open
```


## ๐Ÿงช Testing

Run tests:

```bash
cargo test
```


## ๐Ÿค Contributing

Contributions are welcome! Feel free to open issues or submit pull requests on [GitHub](https://github.com/yourname/wheeltimer).

## ๐Ÿ“„ License

Licensed under either of:
- Apache License, Version 2.0 ([LICENSE-APACHE]LICENSE-APACHE)