From 82aaf985ef2425ce5d35bfe12a164e4ebe0ffe72 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 14 Oct 2026 00:23:21 +0200 Subject: [PATCH] fix not responding to interrupt --- src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3899d22..7871917 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,8 +13,8 @@ use std::hash::{Hash, Hasher}; use std::str::FromStr; use std::sync::atomic::{AtomicBool, Ordering}; use std::thread::sleep; -use std::time::Duration; use syndication::Feed; +use std::time::{Duration, Instant}; use tracing::{debug, error, info, instrument, warn}; use ureq::http::header::{HeaderValue, USER_AGENT}; use ureq::http::Response; @@ -69,7 +69,14 @@ fn main_loop(config: Config) { } } - sleep(config.interval()); + interruptable_sleep(config.interval()); + } +} + +fn interruptable_sleep(duration: Duration) { + let target = Instant::now() + duration; + while Instant::now() < target && RUNNING.load(Ordering::SeqCst) { + sleep(Duration::from_millis(100)); } }