diff options
author | Stephan Dilly <dilly.stephan@gmail.com> | 2021-08-21 19:25:37 +0200 |
---|---|---|
committer | Stephan Dilly <dilly.stephan@gmail.com> | 2021-08-22 00:25:04 +0200 |
commit | 49a1855cbb0b3511dfa157122b250d3f5a73b37b (patch) | |
tree | a6a7bbc5c056ecf7245f9d221b8f4460fffe39e5 | |
parent | eef1a79375b378710b4af392e41da7237928db0b (diff) |
dont use process abort on input thread error (#823)
rather perform a graceful shutdown
-rw-r--r-- | src/app.rs | 4 | ||||
-rw-r--r-- | src/input.rs | 11 |
2 files changed, 11 insertions, 4 deletions
@@ -395,8 +395,8 @@ impl App { } /// - pub const fn is_quit(&self) -> bool { - self.do_quit + pub fn is_quit(&self) -> bool { + self.do_quit || self.input.is_aborted() } /// diff --git a/src/input.rs b/src/input.rs index c2523aa2..3802e61c 100644 --- a/src/input.rs +++ b/src/input.rs @@ -3,7 +3,6 @@ use anyhow::Result; use crossbeam_channel::{unbounded, Receiver, Sender}; use crossterm::event::{self, Event}; use std::{ - process, sync::{ atomic::{AtomicBool, Ordering}, Arc, @@ -33,6 +32,7 @@ pub struct Input { desired_state: Arc<NotifyableMutex<bool>>, current_state: Arc<AtomicBool>, receiver: Receiver<InputEvent>, + aborted: Arc<AtomicBool>, } impl Input { @@ -42,16 +42,18 @@ impl Input { let desired_state = Arc::new(NotifyableMutex::new(true)); let current_state = Arc::new(AtomicBool::new(true)); + let aborted = Arc::new(AtomicBool::new(false)); let arc_desired = Arc::clone(&desired_state); let arc_current = Arc::clone(¤t_state); + let arc_aborted = Arc::clone(&aborted); thread::spawn(move || { if let Err(e) = Self::input_loop(&arc_desired, &arc_current, &tx) { log::error!("input thread error: {}", e); - process::abort(); + arc_aborted.store(true, Ordering::SeqCst); } }); @@ -59,6 +61,7 @@ impl Input { receiver: rx, desired_state, current_state, + aborted, } } @@ -82,6 +85,10 @@ impl Input { != self.current_state.load(Ordering::Relaxed) } + pub fn is_aborted(&self) -> bool { + self.aborted.load(Ordering::SeqCst) + } + fn poll(dur: Duration) -> anyhow::Result<Option<Event>> { if event::poll(dur)? { Ok(Some(event::read()?)) |