From 4ad5bf863df0b4c792a474de5b635a2a6bc65c0e Mon Sep 17 00:00:00 2001 From: Stan Grams Date: Sun, 22 Mar 2026 09:09:59 +0100 Subject: [PATCH] [fix](trx-client): update per-rig state channel on command response send_command only updated the global state_tx watch channel, but SSE sessions subscribe to per-rig rig_states channels. Per-rig channels were only updated during the poll cycle (default 750ms). Now send_command also pushes state to the per-rig channel immediately, eliminating up to 750ms of latency for confirmed frequency/mode/state changes. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Stan Grams --- src/trx-client/src/remote_client.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/trx-client/src/remote_client.rs b/src/trx-client/src/remote_client.rs index efdd014..cce6e5d 100644 --- a/src/trx-client/src/remote_client.rs +++ b/src/trx-client/src/remote_client.rs @@ -344,7 +344,26 @@ async fn send_command( if resp.success { if let Some(snapshot) = resp.state { - let _ = state_tx.send(RigState::from_snapshot(snapshot.clone())); + let new_state = RigState::from_snapshot(snapshot.clone()); + let _ = state_tx.send(new_state.clone()); + // Also update the per-rig watch channel so SSE sessions + // subscribed to a specific rig see the change immediately + // instead of waiting for the next poll cycle. + let rig_id = envelope.rig_id.as_deref(); + if let Some(rid) = rig_id { + if let Ok(map) = config.rig_states.read() { + if let Some(tx) = map.get(rid) { + tx.send_if_modified(|old| { + if *old == new_state { + false + } else { + *old = new_state.clone(); + true + } + }); + } + } + } return Ok(snapshot); } return Err(RigError::communication("missing snapshot"));