[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:
@@ -211,12 +211,20 @@ pub async fn run_rig_task(
|
||||
let _ = state_tx.send(state.clone());
|
||||
|
||||
// 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 {
|
||||
let poll_duration = polling.interval(state.status.tx_en);
|
||||
let mut poll_interval = time::interval(poll_duration);
|
||||
// Update sleep duration if tx_en state changed
|
||||
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! {
|
||||
_ = poll_interval.tick() => {
|
||||
_ = &mut poll_sleep => {
|
||||
poll_sleep = Box::pin(tokio::time::sleep(current_poll_duration));
|
||||
// Check if polling is paused
|
||||
if let Some(until) = poll_pause_until {
|
||||
if Instant::now() < until {
|
||||
|
||||
Reference in New Issue
Block a user