summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2023-11-01 11:18:23 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2023-11-01 11:18:31 -0400
commit5882ff45a34cb92ce920ca21d035d90d463ec679 (patch)
tree1414fb4df15d646fb3dd1a0cea3a847b250082e3
parent7aec4b67557d4ceb4f6949eff20a1c9114d16bab (diff)
make input thread a bit more robust
- this tries to fix the issue where input thread is lagging behind input due to failed message sending
-rw-r--r--src/event/app_event.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/event/app_event.rs b/src/event/app_event.rs
index c0bd9bd..d628517 100644
--- a/src/event/app_event.rs
+++ b/src/event/app_event.rs
@@ -54,7 +54,7 @@ pub struct Config {}
pub struct Events {
pub event_tx: mpsc::Sender<AppEvent>,
event_rx: mpsc::Receiver<AppEvent>,
- pub input_tx: mpsc::SyncSender<()>,
+ pub input_tx: mpsc::Sender<()>,
}
impl Events {
@@ -71,13 +71,17 @@ impl Events {
}
pub fn flush(&self) {
- let _ = self.input_tx.send(());
+ loop {
+ if self.input_tx.send(()).is_ok() {
+ break;
+ }
+ }
}
}
impl std::default::Default for Events {
fn default() -> Self {
- let (input_tx, input_rx) = mpsc::sync_channel(1);
+ let (input_tx, input_rx) = mpsc::channel();
let (event_tx, event_rx) = mpsc::channel();
// edge case that starts off the input thread
@@ -102,7 +106,8 @@ impl std::default::Default for Events {
let stdin = io::stdin();
let mut events = stdin.events();
- while input_rx.recv().is_ok() {
+ loop {
+ let _ = input_rx.recv();
if let Some(Ok(event)) = events.next() {
let _ = event_tx2.send(AppEvent::Termion(event));
}