use super::*;
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct Timer(u64);
impl Timer {
pub fn once(ms: u32, f: impl FnMut() + 'static) -> Timer {
Timer::start(ms, false, f)
}
pub fn every(ms: u32, f: impl FnMut() + 'static) -> Timer {
Timer::start(ms, true, f)
}
fn start(ms: u32, repeat: bool, f: impl FnMut() + 'static) -> Timer {
match core::timer_start(ms, repeat, Box::new(f)) {
Ok(t) => Timer(t),
Err(e) => {
core::set_error(e);
Timer(0)
}
}
}
pub fn stop(&self) {
core::timer_stop(self.0)
}
}