1
0
Fork 0

More documentation

This commit is contained in:
rahix 2024-11-03 20:39:23 +01:00
parent 8d8d347c56
commit ad4fb5d2e2

View file

@ -21,20 +21,22 @@ impl<T: PartialEq> BaseTimer<T> {
self.last = value; self.last = value;
} }
/// Reset the "last" value without triggering change detection /// Returns true if `preset` time has passed since the last value change
pub fn reset_value(&mut self, value: T) {
self.last = value;
}
pub fn timer(&self, now: time::Instant, preset: time::Duration) -> bool { pub fn timer(&self, now: time::Instant, preset: time::Duration) -> bool {
self.change.map(|tt| now >= tt + preset).unwrap_or(true) self.change.map(|tt| now >= tt + preset).unwrap_or(true)
} }
/// Returns the time since the last value change
pub fn timer_value(&self, now: time::Instant) -> time::Duration { pub fn timer_value(&self, now: time::Instant) -> time::Duration {
self.change self.change
.map(|tt| now - tt) .map(|tt| now - tt)
.unwrap_or(time::Duration::ZERO) .unwrap_or(time::Duration::ZERO)
} }
/// Reset the "last" value without triggering change detection
pub fn reset_value(&mut self, value: T) {
self.last = value;
}
} }
pub struct TimerResult { pub struct TimerResult {