Crates.io | hashed_wheel_timer |
lib.rs | hashed_wheel_timer |
version | 0.1.1 |
source | src |
created_at | 2021-08-01 14:40:23.538303 |
updated_at | 2021-08-08 09:53:45.570549 |
description | Rust implementation of the Netty HashedWheelTimer. |
homepage | https://github.com/ZuoFuhong/hashed_wheel_timer |
repository | https://github.com/ZuoFuhong/hashed_wheel_timer |
max_upload_size | |
id | 430029 |
size | 17,704 |
Rust implementation of the Netty HashedWheelTimer.
WARNING: This is a test product. Do not use it in a production deployment.
You only need a stable version of the Rust compiler.
Put the following in your Cargo.toml
:
[dependencies]
hashed_wheel_timer = "0.1.1"
The following bit of code will write the byte string to STDOUT
use hashed_wheel_timer::{TimerTask, WheelTimer};
use std::thread;
use std::time::Duration;
struct ReaderIdleTimeoutTask {
value: u64,
}
impl ReaderIdleTimeoutTask {
fn new(value: u64) -> ReaderIdleTimeoutTask {
ReaderIdleTimeoutTask { value }
}
}
impl TimerTask for ReaderIdleTimeoutTask {
fn run(&mut self) {
println!("ReaderIdleTimeoutTask expire, value {}", self.value)
}
}
fn main() {
let mut timer = WheelTimer::new(500, 10).unwrap();
let task = Box::new(ReaderIdleTimeoutTask::new(100));
timer.new_timeout(task, Duration::new(1, 0));
thread::sleep(Duration::new(5, 0))
}