5 releases
Uses old Rust 2015
0.1.4 | May 23, 2022 |
---|---|
0.1.3 | May 22, 2022 |
0.1.2 | May 22, 2022 |
0.1.1 | May 22, 2022 |
0.1.0 | May 22, 2022 |
#12 in #factory
21 downloads per month
11KB
237 lines
#tunm_timer
简易定时器
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;
}
}
}
Dependencies
~54KB