Merge 4438e61dac
into 581c0a02c0
This commit is contained in:
commit
263f21d042
26
src/lib.rs
26
src/lib.rs
|
@ -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 }
|
||||
|
|
Loading…
Reference in New Issue