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)); } }