From ad50695e41f5044aecd4cc5987d40d97aaad1c9d Mon Sep 17 00:00:00 2001 From: Asuna Date: Mon, 5 Feb 2024 14:41:04 +0800 Subject: [PATCH] Check `active` even if `Condvar` times out in `PeriodicWorker` --- spdlog/src/periodic_worker.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spdlog/src/periodic_worker.rs b/spdlog/src/periodic_worker.rs index 032bfa85..e9938cdb 100644 --- a/spdlog/src/periodic_worker.rs +++ b/spdlog/src/periodic_worker.rs @@ -21,13 +21,13 @@ impl PeriodicWorker { Self { active: active.clone(), thread: Some(thread::spawn(move || loop { - let guard = active.0.lock_expect(); - let (_, res) = active + let flag = active.0.lock_expect(); + let (flag, res) = active .1 - .wait_timeout_while(guard, interval, |active| *active) + .wait_timeout_while(flag, interval, |flag| *flag) .unwrap(); - if !res.timed_out() || !callback() { + if !res.timed_out() || !*flag || !callback() { return; } })),