diff options
author | Carl Lerche <me@carllerche.com> | 2019-11-15 22:11:13 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-15 22:11:13 -0800 |
commit | 8a7e57786a5dca139f5b4261685e22991ded0859 (patch) | |
tree | b69d1c48f8a760a58fc7ccfe0376d9812a88d303 /tokio/src/process/mod.rs | |
parent | 930679587ae42e4df3113159ccf33fb5923dd73a (diff) |
Limit `futures` dependency to `Stream` via feature flag (#1774)
In an effort to reach API stability, the `tokio` crate is shedding its
_public_ dependencies on crates that are either a) do not provide a
stable (1.0+) release with longevity guarantees or b) match the `tokio`
release cadence. Of course, implementing `std` traits fits the
requirements.
The on exception, for now, is the `Stream` trait found in `futures_core`.
It is expected that this trait will not change much and be moved into `std.
Since Tokio is not yet going reaching 1.0, I feel that it is acceptable to maintain
a dependency on this trait given how foundational it is.
Since the `Stream` implementation is optional, types that are logically
streams provide `async fn next_*` functions to obtain the next value.
Avoiding the `next()` name prevents fn conflicts with `StreamExt::next()`.
Additionally, some misc cleanup is also done:
- `tokio::io::io` -> `tokio::io::util`.
- `delay` -> `delay_until`.
- `Timeout::new` -> `timeout(...)`.
- `signal::ctrl_c()` returns a future instead of a stream.
- `{tcp,unix}::Incoming` is removed (due to lack of `Stream` trait).
- `time::Throttle` is removed (due to lack of `Stream` trait).
- Fix: `mpsc::UnboundedSender::send(&self)` (no more conflict with `Sink` fns).
Diffstat (limited to 'tokio/src/process/mod.rs')
-rw-r--r-- | tokio/src/process/mod.rs | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/tokio/src/process/mod.rs b/tokio/src/process/mod.rs index e777da52..3013a65a 100644 --- a/tokio/src/process/mod.rs +++ b/tokio/src/process/mod.rs @@ -58,7 +58,6 @@ //! use tokio::io::{BufReader, AsyncBufReadExt}; //! use tokio::process::Command; //! -//! use futures_util::stream::StreamExt; //! use std::process::Stdio; //! //! #[tokio::main] @@ -89,8 +88,8 @@ //! println!("child status was: {}", status); //! }); //! -//! while let Some(line) = reader.next().await { -//! println!("Line: {}", line?); +//! while let Some(line) = reader.next_line().await? { +//! println!("Line: {}", line); //! } //! //! Ok(()) @@ -120,8 +119,6 @@ mod kill; use crate::io::{AsyncRead, AsyncReadExt, AsyncWrite}; use crate::process::kill::Kill; -use futures_core::TryFuture; -use futures_util::future::try_join3; use std::ffi::OsStr; use std::future::Future; use std::io; @@ -681,11 +678,14 @@ impl<T: Kill> Drop for ChildDropGuard<T> { } } -impl<T: TryFuture + Kill + Unpin> Future for ChildDropGuard<T> { - type Output = Result<T::Ok, T::Error>; +impl<T, E, F> Future for ChildDropGuard<F> +where + F: Future<Output = Result<T, E>> + Kill + Unpin, +{ + type Output = Result<T, E>; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { - let ret = Pin::new(&mut self.inner).try_poll(cx); + let ret = Pin::new(&mut self.inner).poll(cx); if let Poll::Ready(Ok(_)) = ret { // Avoid the overhead of trying to kill a reaped process @@ -766,6 +766,8 @@ impl Child { /// new pipes between parent and child. Use `stdout(Stdio::piped())` or /// `stderr(Stdio::piped())`, respectively, when creating a `Command`. pub async fn wait_with_output(mut self) -> io::Result<Output> { + use crate::future::try_join3; + async fn read_to_end<A: AsyncRead + Unpin>(io: Option<A>) -> io::Result<Vec<u8>> { let mut vec = Vec::new(); if let Some(mut io) = io { @@ -940,16 +942,14 @@ mod sys { #[cfg(all(test, not(loom)))] mod test { + use super::kill::Kill; + use super::ChildDropGuard; + + use futures::future::FutureExt; use std::future::Future; use std::io; use std::pin::Pin; - use std::task::Context; - use std::task::Poll; - - use futures_util::future::FutureExt; - - use super::kill::Kill; - use super::ChildDropGuard; + use std::task::{Context, Poll}; struct Mock { num_kills: usize, @@ -1021,7 +1021,7 @@ mod test { let mut mock_reaped = Mock::with_result(Poll::Ready(Ok(()))); let mut mock_err = Mock::with_result(Poll::Ready(Err(()))); - let waker = futures_util::task::noop_waker(); + let waker = futures::task::noop_waker(); let mut context = Context::from_waker(&waker); { let mut guard = ChildDropGuard::new(&mut mock_pending); |