summaryrefslogtreecommitdiffstats
path: root/src/shell/history/mod.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-01-09 03:38:55 -0500
committerJesse Luehrs <doy@tozt.net>2022-01-09 03:38:55 -0500
commit27ad465ce178aa9bc51d2bea2b5c5c1a77089138 (patch)
tree0d4731a36712a315b6efdebc26f48b7cba96ee9e /src/shell/history/mod.rs
parent6286c1284f62b9ea2d7144daae7ff9abf7d474c6 (diff)
downloadnbsh-27ad465ce178aa9bc51d2bea2b5c5c1a77089138.tar.gz
nbsh-27ad465ce178aa9bc51d2bea2b5c5c1a77089138.zip
don't busy loop when waiting for exit after exit event
Diffstat (limited to 'src/shell/history/mod.rs')
-rw-r--r--src/shell/history/mod.rs39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/shell/history/mod.rs b/src/shell/history/mod.rs
index b280940..acdc439 100644
--- a/src/shell/history/mod.rs
+++ b/src/shell/history/mod.rs
@@ -535,29 +535,34 @@ async fn run_pipeline(
let read_r = read_r.clone();
let read = async move { Res::Read(read_r.recv().await.unwrap()) };
- let exit = async { Res::Exit(child.status_no_drop().await) };
+ let exit = async {
+ Res::Exit(if exit_done.is_none() {
+ child.status_no_drop().await
+ } else {
+ std::future::pending().await
+ })
+ };
match read.or(exit).await {
- Res::Read(Ok(event)) => {
- match event {
- crate::pipeline::Event::Suspend(idx) => {
- event_w.send(Event::ChildSuspend(idx)).await.unwrap();
- }
- crate::pipeline::Event::Exit(new_env) => {
- *env = new_env;
- read_done = true;
- continue;
- }
+ Res::Read(Ok(event)) => match event {
+ crate::pipeline::Event::Suspend(idx) => {
+ event_w.send(Event::ChildSuspend(idx)).await.unwrap();
+ new_read();
}
- new_read();
- }
+ crate::pipeline::Event::Exit(new_env) => {
+ *env = new_env;
+ read_done = true;
+ }
+ },
Res::Read(Err(e)) => {
- if let bincode::ErrorKind::Io(e) = &*e {
- if e.kind() == std::io::ErrorKind::UnexpectedEof {
+ if let bincode::ErrorKind::Io(io_e) = &*e {
+ if io_e.kind() == std::io::ErrorKind::UnexpectedEof {
read_done = true;
- continue;
+ } else {
+ anyhow::bail!(e);
}
+ } else {
+ anyhow::bail!(e);
}
- anyhow::bail!(e);
}
Res::Exit(Ok(status)) => {
exit_done = Some(status);