Fix (hopefully) timer_execute fn

This commit is contained in:
Stephen Seo 2022-02-06 14:35:16 +09:00
parent f408df0de2
commit 37755fdcb6

View file

@ -123,12 +123,13 @@ fn timer_execute<F>(func: F, sleep_seconds: u64) -> Result<(), String>
where where
F: std::ops::Fn() -> Result<(), String>, F: std::ops::Fn() -> Result<(), String>,
{ {
let mut instant = Instant::now(); let mut instant = Instant::now() - Duration::from_secs(sleep_seconds);
let diff_duration = Duration::from_secs(sleep_seconds * 2);
let mut duration: Duration; let mut duration: Duration;
loop { loop {
func()?; func()?;
let newer_instant = Instant::now(); let newer_instant = Instant::now();
duration = Duration::from_secs(sleep_seconds) - (newer_instant - instant); duration = diff_duration - (newer_instant - instant);
instant = newer_instant; instant = newer_instant;
sleep(duration); sleep(duration);
} }