From 004a54c4ae068baee1d257aa42173bb818a86fc5 Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 6 Jan 2024 17:47:44 -0600 Subject: [PATCH] Improve cooperation from background jobs --- src/queue.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/queue.rs b/src/queue.rs index 501d66c..17bd0bd 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -446,8 +446,18 @@ where let mut hb = None; + let yield_limit = 8; + let mut count = 0; + loop { tracing::trace!("heartbeat: looping"); + count += 1; + count = count % yield_limit; + + // yield every 8 iterations to be kind to other tasks + if count == 0 { + tokio::task::yield_now().await; + } tokio::select! { output = &mut fut => {