mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
fix: process LTC frames in background to update app state
Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
parent
985ccc6819
commit
6a45660e03
1 changed files with 13 additions and 9 deletions
22
src/main.rs
22
src/main.rs
|
|
@ -151,19 +151,23 @@ async fn main() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8️⃣ Keep main thread alive
|
// 8️⃣ Main logic loop: process frames from serial and update state
|
||||||
|
let loop_state = ltc_state.clone();
|
||||||
|
let logic_task = task::spawn_blocking(move || {
|
||||||
|
for frame in rx {
|
||||||
|
loop_state.lock().unwrap().update(frame);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 9️⃣ Keep main thread alive
|
||||||
if args.command.is_some() {
|
if args.command.is_some() {
|
||||||
// In daemon mode, wait forever.
|
// In daemon mode, wait forever. The logic_task runs in the background.
|
||||||
std::future::pending::<()>().await;
|
std::future::pending::<()>().await;
|
||||||
} else {
|
} else {
|
||||||
// In TUI mode, block on the channel.
|
// In TUI mode, block until the logic_task finishes (e.g. serial port disconnects)
|
||||||
|
// This keeps the TUI running.
|
||||||
log::info!("📡 Main thread entering loop...");
|
log::info!("📡 Main thread entering loop...");
|
||||||
let _ = task::spawn_blocking(move || {
|
let _ = logic_task.await;
|
||||||
for _frame in rx {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue