From de9b4014574c5be477d7566c03147165cb84e2f5 Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Sun, 8 Apr 2018 15:55:26 -0700 Subject: [PATCH] process: Mark status_async2/StatusAsync2 as deprecated --- src/lib.rs | 43 +++++++++++++++++++++++++++++++++++++------ tests/stdio.rs | 6 +++--- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 774a9fe0e..8b84abfa8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -169,6 +169,29 @@ pub trait CommandExt { /// event loop. fn spawn_async(&mut self, handle: &Handle) -> io::Result; + /// Executes a command as a child process, waiting for it to finish and + /// collecting its exit status. + /// + /// By default, stdin, stdout and stderr are inherited from the parent. + /// + /// The `StatusAsync` future returned will resolve to the `ExitStatus` + /// type in the standard library representing how the process exited. If + /// any input/output handles are set to a pipe then they will be immediately + /// closed after the child is spawned. + /// + /// The `handle` specified must be a handle to a valid event loop, and all + /// I/O this child does will be associated with the specified event loop. + /// + /// If the `StatusAsync` future is dropped before the future resolves, then + /// the child will be killed, if it was spawned. + /// + /// # Errors + /// + /// This function will return an error immediately if the child process + /// cannot be spawned. Otherwise errors obtained while waiting for the child + /// are returned through the `StatusAsync` future. + fn status_async(&mut self, handle: &Handle) -> io::Result; + /// Executes a command as a child process, waiting for it to finish and /// collecting its exit status. /// @@ -190,7 +213,11 @@ pub trait CommandExt { /// This function will return an error immediately if the child process /// cannot be spawned. Otherwise errors obtained while waiting for the child /// are returned through the `StatusAsync2` future. - fn status_async2(&mut self, handle: &Handle) -> io::Result; + #[doc(hidden)] + #[deprecated(note = "renamed to `status_async`", since = "0.2.1")] + fn status_async2(&mut self, handle: &Handle) -> io::Result { + self.status_async(handle) + } /// Executes the command as a child process, waiting for it to finish and /// collecting all of its output. @@ -237,7 +264,7 @@ impl CommandExt for process::Command { Ok(child) } - fn status_async2(&mut self, handle: &Handle) -> io::Result { + fn status_async(&mut self, handle: &Handle) -> io::Result { self.spawn_async(handle).map(|mut child| { // Ensure we close any stdio handles so we can't deadlock // waiting on the child which may be waiting to read/write @@ -246,7 +273,7 @@ impl CommandExt for process::Command { child.stdout.take(); child.stderr.take(); - StatusAsync2 { + StatusAsync { inner: child, } }) @@ -438,18 +465,22 @@ impl Future for WaitWithOutput { } } -/// Future returned by the `CommandExt::status_async2` method. +#[doc(hidden)] +#[deprecated(note = "renamed to `StatusAsync`", since = "0.2.1")] +pub type StatusAsync2 = StatusAsync; + +/// Future returned by the `CommandExt::status_async` method. /// /// This future is used to conveniently spawn a child and simply wait for its /// exit status. This future will resolves to the `ExitStatus` type in the /// standard library. #[must_use = "futures do nothing unless polled"] #[derive(Debug)] -pub struct StatusAsync2 { +pub struct StatusAsync { inner: Child, } -impl Future for StatusAsync2 { +impl Future for StatusAsync { type Item = ExitStatus; type Error = io::Error; diff --git a/tests/stdio.rs b/tests/stdio.rs index 25e9fcd34..dd8a96adf 100644 --- a/tests/stdio.rs +++ b/tests/stdio.rs @@ -120,13 +120,13 @@ fn wait_with_output_captures() { } #[test] -fn status2_closes_any_pipes() { +fn status_closes_any_pipes() { let mut core = Core::new().unwrap(); // Cat will open a pipe between the parent and child. - // If `status_async2` doesn't ensure the handles are closed, + // If `status_async` doesn't ensure the handles are closed, // we would end up blocking forever (and time out). - let child = cat().status_async2(&core.handle()).unwrap(); + let child = cat().status_async(&core.handle()).unwrap(); let timeout = Timeout::new(Duration::from_secs(1), &core.handle()) .expect("timeout registration failed") .map(|()| panic!("time out exceeded! did we get stuck waiting on the child?"));