diff --git a/src/time.rs b/src/time.rs index a59a2c7..6e0d522 100644 --- a/src/time.rs +++ b/src/time.rs @@ -23,9 +23,17 @@ impl Periodically { } pub fn run(&mut self, f: F) where F: FnOnce() { - if self.last_run.elapsed() >= self.duration { + if self.tick() { f(); + } + } + + pub fn tick(&mut self) -> bool { + if self.last_run.elapsed() >= self.duration { self.last_run = Instant::now(); + true + } else { + false } } }