tunm_timer

Crates.iotunm_timer
lib.rstunm_timer
version0.1.4
sourcesrc
created_at2022-05-22 11:38:30.101759
updated_at2022-05-23 03:39:36.713829
descriptionsimple timer, 简易定时器
homepage
repositoryhttps://github.com/tickbh/tunm
max_upload_size
id591114
size23,055
问蒙框架服务 (tickbh)

documentation

README

#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;
        }
    }
}
Commit count: 180

cargo fmt