2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 11:21:24 +00:00

Improve cooperation from background jobs

This commit is contained in:
asonix 2024-01-06 17:47:44 -06:00
parent bcf73eb4e4
commit 004a54c4ae

View file

@ -446,8 +446,18 @@ where
let mut hb = None; let mut hb = None;
let yield_limit = 8;
let mut count = 0;
loop { loop {
tracing::trace!("heartbeat: looping"); 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! { tokio::select! {
output = &mut fut => { output = &mut fut => {