Crates.io | tunm_timer |
lib.rs | tunm_timer |
version | 0.1.4 |
source | src |
created_at | 2022-05-22 11:38:30.101759 |
updated_at | 2022-05-23 03:39:36.713829 |
description | simple timer, 简易定时器 |
homepage | |
repository | https://github.com/tickbh/tunm |
max_upload_size | |
id | 591114 |
size | 23,055 |
简易定时器
extern crate tunm_timer;
use tunm_timer::{Factory, Timer, RetTimer, Handler};
struct TimeHandle;
impl tunm_timer::Factory for TimeHandle {
fn on_trigger(&mut self, timer: &mut Timer<Self>, id: u64) -> RetTimer {
println!("ontigger = {:}", id);
RetTimer::Ok
}
}
struct RepeatTimeHandle {
times: u32,
}
impl tunm_timer::Factory for RepeatTimeHandle {
fn on_trigger(&mut self, timer: &mut Timer<Self>, id: u64) -> RetTimer {
self.times += 1;
if self.times > 10 {
return RetTimer::Over;
}
println!("ontigger = {:} self.times = {}", id, self.times);
RetTimer::Ok
// timer.add_timer(mut handle: Handler<F>)
}
}
fn main() {
println!("ok");
let mut timer = Timer::new(u64::MAX);
let time1 = timer.add_timer(Handler::new_step(
RepeatTimeHandle{times:0}, 1000_000, true, true));
println!("time == {}", time1);
loop {
timer.tick_time(tunm_timer::now_microsecond());
if timer.is_empty() {
break;
}
}
}