Function goose::util::timer_expired [−][src]
Expand description
Determine if a timer expired, with second granularity.
If the timer was started more than run_time
seconds ago return true
, otherwise
return false
.
This function accepts started as a
std::time::Instant
. It
expects run_time
in seconds.
Example
use goose::util;
let started = std::time::Instant::now();
let mut counter = 0;
loop {
// Track how many times this loop runs.
counter += 1;
// Sleep for a quarter of a second.
std::thread::sleep(std::time::Duration::from_millis(250));
// Do stuff ...
// Loop until the timer expires, then break.
if util::timer_expired(started, 1) {
break
}
}
// It took 4 loops for the timer to expire.
assert_eq!(counter, 4);