This commit is contained in:
Jesse Luehrs 2024-04-06 07:16:43 -07:00 committed by GitHub
commit 263f21d042
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 1 deletions

View File

@ -339,7 +339,7 @@ impl Child {
/// }
/// # std::io::Result::Ok(()) });
/// ```
pub fn try_status(&mut self) -> io::Result<Option<ExitStatus>> {
pub fn try_status(&self) -> io::Result<Option<ExitStatus>> {
self.child.lock().unwrap().get_mut().try_wait()
}
@ -365,6 +365,30 @@ impl Child {
/// ```
pub fn status(&mut self) -> impl Future<Output = io::Result<ExitStatus>> {
self.stdin.take();
self.status_no_drop()
}
/// Waits for the process to exit.
///
/// Unlike `status`, does not drop the stdin handle. You are responsible
/// for avoiding deadlocks caused by the child blocking on stdin while the
/// parent blocks on waiting for the process to exit.
///
/// # Examples
///
/// ```no_run
/// # futures_lite::future::block_on(async {
/// use async_process::{Command, Stdio};
///
/// let child = Command::new("cp")
/// .arg("a.txt")
/// .arg("b.txt")
/// .spawn()?;
///
/// println!("exit status: {}", child.status_no_drop().await?);
/// # std::io::Result::Ok(()) });
/// ```
pub fn status_no_drop(&self) -> impl Future<Output = io::Result<ExitStatus>> {
let child = self.child.clone();
async move { Reaper::get().sys.status(&child).await }