Skip to content

Commit b1bacbe

Browse files
author
Stephan Dilly
committed
dont use process abort on input thread error (#823)
rather perform a graceful shutdown
1 parent eef1a79 commit b1bacbe

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/app.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ impl App {
395395
}
396396

397397
///
398-
pub const fn is_quit(&self) -> bool {
399-
self.do_quit
398+
pub fn is_quit(&self) -> bool {
399+
self.do_quit || self.input.is_aborted()
400400
}
401401

402402
///

src/input.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use anyhow::Result;
33
use crossbeam_channel::{unbounded, Receiver, Sender};
44
use crossterm::event::{self, Event};
55
use std::{
6-
process,
76
sync::{
87
atomic::{AtomicBool, Ordering},
98
Arc,
@@ -33,6 +32,7 @@ pub struct Input {
3332
desired_state: Arc<NotifyableMutex<bool>>,
3433
current_state: Arc<AtomicBool>,
3534
receiver: Receiver<InputEvent>,
35+
aborted: Arc<AtomicBool>,
3636
}
3737

3838
impl Input {
@@ -42,23 +42,26 @@ impl Input {
4242

4343
let desired_state = Arc::new(NotifyableMutex::new(true));
4444
let current_state = Arc::new(AtomicBool::new(true));
45+
let aborted = Arc::new(AtomicBool::new(false));
4546

4647
let arc_desired = Arc::clone(&desired_state);
4748
let arc_current = Arc::clone(&current_state);
49+
let arc_aborted = Arc::clone(&aborted);
4850

4951
thread::spawn(move || {
5052
if let Err(e) =
5153
Self::input_loop(&arc_desired, &arc_current, &tx)
5254
{
5355
log::error!("input thread error: {}", e);
54-
process::abort();
56+
arc_aborted.store(true, Ordering::SeqCst);
5557
}
5658
});
5759

5860
Self {
5961
receiver: rx,
6062
desired_state,
6163
current_state,
64+
aborted,
6265
}
6366
}
6467

@@ -82,6 +85,10 @@ impl Input {
8285
!= self.current_state.load(Ordering::Relaxed)
8386
}
8487

88+
pub fn is_aborted(&self) -> bool {
89+
self.aborted.load(Ordering::SeqCst)
90+
}
91+
8592
fn poll(dur: Duration) -> anyhow::Result<Option<Event>> {
8693
if event::poll(dur)? {
8794
Ok(Some(event::read()?))

0 commit comments

Comments
 (0)