From 5a8aab1cb5dc501947d760e11bb1c817274a3e7f Mon Sep 17 00:00:00 2001 From: SilverMira <66930495+SilverMira@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:27:55 +0800 Subject: [PATCH] fix: remove 100ms delay on first and subsequent read calls Currently, there is an unnecessary wait with `recv_timeout()` on reader thread which causes reading from pipe to have an inherent 100ms wait time. Similarly, cache thread also has this issue, where read() calls are served throttled with a 100ms delay --- src/pty/base.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pty/base.rs b/src/pty/base.rs index 7c371bc..62075d9 100644 --- a/src/pty/base.rs +++ b/src/pty/base.rs @@ -359,7 +359,7 @@ impl PTYProcess { // let mut alive = reader_alive_rx.recv_timeout(Duration::from_millis(300)).unwrap_or(true); // alive = alive && !is_eof(process, conout).unwrap(); - while reader_alive_rx.recv_timeout(Duration::from_millis(100)).unwrap_or(true) { + while reader_alive_rx.try_recv().unwrap_or(true) { if !is_eof(process, conout).unwrap() { let result = read(4096, true, conout, using_pipes); reader_out_tx.send(Some(result)).unwrap(); @@ -378,7 +378,7 @@ impl PTYProcess { let cache_thread = thread::spawn(move || { let mut read_buf = OsString::new(); - while cache_alive_rx.recv_timeout(Duration::from_millis(100)).unwrap_or(true) { + while cache_alive_rx.try_recv().unwrap_or(true) { if let Ok(Some((length, blocking))) = cache_req_rx.recv() { let mut pending_read: Option = None;