From e51262fbd3095d3df254b9a95e6240b3af5455cb Mon Sep 17 00:00:00 2001 From: Payton McIntosh Date: Wed, 24 Dec 2025 00:15:20 +0000 Subject: [PATCH] Prioritize shutdown in wait_or_shutdown select MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add `biased;` directive to the tokio::select! macro and reorder the arms so the shutdown branch is checked first. This ensures that when both the sleep timer and shutdown signal are ready simultaneously, shutdown is always selected, providing more responsive graceful shutdown behaviour. Fixes #87 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- crates/comenqd/src/worker.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/comenqd/src/worker.rs b/crates/comenqd/src/worker.rs index b05ece9..20e39e5 100644 --- a/crates/comenqd/src/worker.rs +++ b/crates/comenqd/src/worker.rs @@ -122,8 +122,9 @@ impl WorkerHooks { /// without indicating which occurred. Passing `secs = 0` returns immediately. pub async fn wait_or_shutdown(secs: u64, shutdown: &mut watch::Receiver<()>) { tokio::select! { - _ = tokio::time::sleep(Duration::from_secs(secs)) => {}, + biased; _ = shutdown.changed() => {}, + _ = tokio::time::sleep(Duration::from_secs(secs)) => {}, } } }