time: add a tick() function to Periodically to avoid needing Fn

This commit is contained in:
Victoria Fischer 2024-11-30 16:05:01 +01:00
parent 94567b9b60
commit 57e660cbb6

View File

@ -23,9 +23,17 @@ impl Periodically {
} }
pub fn run<F>(&mut self, f: F) where F: FnOnce() { pub fn run<F>(&mut self, f: F) where F: FnOnce() {
if self.last_run.elapsed() >= self.duration { if self.tick() {
f(); f();
}
}
pub fn tick(&mut self) -> bool {
if self.last_run.elapsed() >= self.duration {
self.last_run = Instant::now(); self.last_run = Instant::now();
true
} else {
false
} }
} }
} }