mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-20 00:00:08 +02:00
process: Mark status_async2/StatusAsync2 as deprecated
This commit is contained in:
+37
-6
@@ -169,6 +169,29 @@ pub trait CommandExt {
|
||||
/// event loop.
|
||||
fn spawn_async(&mut self, handle: &Handle) -> io::Result<Child>;
|
||||
|
||||
/// 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<StatusAsync>;
|
||||
|
||||
/// 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<StatusAsync2>;
|
||||
#[doc(hidden)]
|
||||
#[deprecated(note = "renamed to `status_async`", since = "0.2.1")]
|
||||
fn status_async2(&mut self, handle: &Handle) -> io::Result<StatusAsync> {
|
||||
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<StatusAsync2> {
|
||||
fn status_async(&mut self, handle: &Handle) -> io::Result<StatusAsync> {
|
||||
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;
|
||||
|
||||
|
||||
+3
-3
@@ -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?"));
|
||||
|
||||
Reference in New Issue
Block a user