Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,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()
}

Expand All @@ -352,6 +352,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 {
Expand Down