[fix](trx-server): fix busy-loop in rig polling caused by interval recreation

time::interval() fires its first tick immediately. Recreating it on
every loop iteration made the select! always resolve instantly,
turning the main polling loop into a busy-loop (~13% CPU idle).

Replace with a Box::pin(sleep()) that is only reset after it
completes or when the poll duration changes (rx/tx transition).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
2026-02-07 15:14:31 +01:00
parent 75de1e50b9
commit b142d68ca2
+11 -3
View File
@@ -211,12 +211,20 @@ pub async fn run_rig_task(
let _ = state_tx.send(state.clone()); let _ = state_tx.send(state.clone());
// Main task loop // Main task loop
let mut current_poll_duration = polling.interval(state.status.tx_en);
let mut poll_sleep: std::pin::Pin<Box<tokio::time::Sleep>> =
Box::pin(tokio::time::sleep(current_poll_duration));
loop { loop {
let poll_duration = polling.interval(state.status.tx_en); // Update sleep duration if tx_en state changed
let mut poll_interval = time::interval(poll_duration); let new_duration = polling.interval(state.status.tx_en);
if new_duration != current_poll_duration {
current_poll_duration = new_duration;
poll_sleep = Box::pin(tokio::time::sleep(current_poll_duration));
}
tokio::select! { tokio::select! {
_ = poll_interval.tick() => { _ = &mut poll_sleep => {
poll_sleep = Box::pin(tokio::time::sleep(current_poll_duration));
// Check if polling is paused // Check if polling is paused
if let Some(until) = poll_pause_until { if let Some(until) = poll_pause_until {
if Instant::now() < until { if Instant::now() < until {