mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
fix: run API server in LocalSet to fix spawn_local panic
Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
parent
c94e1ea4b0
commit
2d6f65046a
1 changed files with 25 additions and 15 deletions
16
src/main.rs
16
src/main.rs
|
|
@ -18,7 +18,7 @@ use std::{
|
|||
sync::{Arc, Mutex, mpsc},
|
||||
thread,
|
||||
};
|
||||
use tokio::task;
|
||||
use tokio::task::{self, LocalSet};
|
||||
|
||||
/// Embed the default config.json at compile time.
|
||||
const DEFAULT_CONFIG: &str = include_str!("../config.json");
|
||||
|
|
@ -77,7 +77,11 @@ async fn main() {
|
|||
});
|
||||
}
|
||||
|
||||
// 6️⃣ Spawn the API server thread
|
||||
// 6️⃣ Set up a LocalSet for the API server.
|
||||
let local = LocalSet::new();
|
||||
local
|
||||
.run_until(async move {
|
||||
// 7️⃣ Spawn the API server thread
|
||||
{
|
||||
let api_state = ltc_state.clone();
|
||||
let offset_clone = hw_offset.clone();
|
||||
|
|
@ -88,11 +92,17 @@ async fn main() {
|
|||
});
|
||||
}
|
||||
|
||||
// 7️⃣ Keep main thread alive by processing LTC frames
|
||||
// 8️⃣ Keep main thread alive by consuming LTC frames in a blocking task
|
||||
println!("📡 Main thread entering loop...");
|
||||
let _ = task::spawn_blocking(move || {
|
||||
// This will block the thread, but it's a blocking-safe thread.
|
||||
for _frame in rx {
|
||||
// no-op
|
||||
}
|
||||
})
|
||||
.await;
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue