generated from GarandPLG/rust-flake-template
Join input thread before exiting
Store the input event thread handle and join it after the app finishes. This replaces the previous fire‑and‑forget spawn and ensures the thread is cleanly terminated before the program exits.
This commit is contained in:
1 parent
dd64ef78f7
commit
92ace142b4
1 file changed
+4
-2
+4
-2
@@ -2,7 +2,7 @@ use ratatui::{Terminal, prelude::CrosstermBackend};
|
|||||||
use std::{
|
use std::{
|
||||||
io::{Result, Stdout},
|
io::{Result, Stdout},
|
||||||
sync::mpsc::{Sender, channel},
|
sync::mpsc::{Sender, channel},
|
||||||
thread,
|
thread::{self, JoinHandle},
|
||||||
};
|
};
|
||||||
use war_in_tunnels::{
|
use war_in_tunnels::{
|
||||||
app::{App, AppEvent, handle_input_events},
|
app::{App, AppEvent, handle_input_events},
|
||||||
@@ -27,12 +27,14 @@ fn main() -> Result<()> {
|
|||||||
let (event_tx, event_rx) = channel::<AppEvent>();
|
let (event_tx, event_rx) = channel::<AppEvent>();
|
||||||
|
|
||||||
let tx_to_input_events: Sender<AppEvent> = event_tx.clone();
|
let tx_to_input_events: Sender<AppEvent> = event_tx.clone();
|
||||||
thread::spawn(move || {
|
let input_thread: JoinHandle<()> = thread::spawn(move || {
|
||||||
handle_input_events(tx_to_input_events);
|
handle_input_events(tx_to_input_events);
|
||||||
});
|
});
|
||||||
|
|
||||||
let app_result: Result<()> = app.run(&mut terminal, event_rx);
|
let app_result: Result<()> = app.run(&mut terminal, event_rx);
|
||||||
ratatui::restore();
|
ratatui::restore();
|
||||||
|
|
||||||
|
let _ = input_thread.join();
|
||||||
|
|
||||||
app_result
|
app_result
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user