From 27ad465ce178aa9bc51d2bea2b5c5c1a77089138 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 9 Jan 2022 03:38:55 -0500 Subject: don't busy loop when waiting for exit after exit event --- src/shell/history/mod.rs | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'src/shell/history/mod.rs') 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); -- cgit v1.2.3-54-g00ecf