From 803084af12355b342eb6b8f3596831d65e0160a1 Mon Sep 17 00:00:00 2001 From: Florian Stecker Date: Mon, 2 Jan 2023 10:54:44 +0100 Subject: [PATCH] overflow check when timer expired while disconnected --- src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index c0fa1a4..3feced1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,7 +104,12 @@ pub fn run() -> AResult<()> { wait_time = interval_duration; } else { - wait_time = interval_duration - elapsed; + // wait for the remaining time until interval_duration + // if the time is already up, that means we're not connected currently + // in that case, just wait 1/2 hour, once the connection is reestablished + // the main thread will unpark us anyway + wait_time = interval_duration.checked_sub(elapsed) + .unwrap_or(Duration::from_secs(1800)); } } })