time: add a tick() function to Periodically to avoid needing Fn
This commit is contained in:
parent
94567b9b60
commit
57e660cbb6
10
src/time.rs
10
src/time.rs
@ -23,9 +23,17 @@ impl Periodically {
|
||||
}
|
||||
|
||||
pub fn run<F>(&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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user