add status_no_drop which takes &self and doesn't drop stdin
this is a much more useful capability for an async process library, since it is much easier to avoid blocking on this call (since it is a future)
This commit is contained in:
parent
61e10f81be
commit
4438e61dac
24
src/lib.rs
24
src/lib.rs
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue