mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 00:48:35 +00:00
dont use process abort on input thread error (#823)
rather perform a graceful shutdown
This commit is contained in:
parent
eef1a79375
commit
49a1855cbb
2 changed files with 11 additions and 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()
|
||||
}
|
||||
|
||||
///
|
||||
|
|
|
|||
11
src/input.rs
11
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()?))
|
||||
|
|
|
|||
Loading…
Reference in a new issue