From 212bfb2bfc2e804101b1545d8b04ff41ba83360d Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Mon, 28 Oct 2019 17:39:57 +0100 Subject: [PATCH 01/10] init Future::select Signed-off-by: Yoshua Wuyts --- src/future/future.rs | 34 ++++++++++++++++++++++++++++++++++ src/future/mod.rs | 28 +++++++++++++++------------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/future/future.rs b/src/future/future.rs index fe685176a..4b8360686 100644 --- a/src/future/future.rs +++ b/src/future/future.rs @@ -129,6 +129,40 @@ extension_trait! { { DelayFuture::new(self, dur) } + + #[doc = r#" + Waits for either one of several similarly-typed futures to complete. + + Awaits multiple futures simultaneously, returning all results once complete. + + This function will return a new future which awaits for either one of both + futures to complete. If multiple futures are completed at the same time, + resolution will occur in the order that they have been passed. + + Note that this macro consumes all futures passed, and once a future is + completed, all other futures are dropped. + + This macro is only usable inside of async functions, closures, and blocks. + + # Examples + + ``` + #![feature(async_await)] + # futures::executor::block_on(async { + use futures::future; + + let a = future::pending(); + let b = future::ready(1u8); + let c = future::ready(2u8); + + let f = a.select(b).select(c); + assert_eq!(f.await, 1u8); + # }); + ``` + "#] + fn select(&mut self) -> () { + () + } } impl Future for Box { diff --git a/src/future/mod.rs b/src/future/mod.rs index a45bf96cd..7789ddee3 100644 --- a/src/future/mod.rs +++ b/src/future/mod.rs @@ -10,10 +10,10 @@ //! //! For operating on futures the following macros can be used: //! -//! | Name | Return signature | When does it return? | -//! | --- | --- | --- | -//! | `future::join` | `(T1, T2)` | Wait for all to complete -//! | `future::select` | `T` | Return on first value +//! | Name | Return signature | When does it return? | +//! | --- | --- | --- | +//! | [`future::join!`] | `(T1, T2)` | Wait for all to complete +//! | [`Future::select`] | `T` | Return on first value //! //! ## Fallible Futures Concurrency //! @@ -34,12 +34,17 @@ //! even on futures that return `Result`. Here is an overview of operations that //! work on `Result`, and their respective semantics: //! -//! | Name | Return signature | When does it return? | -//! | --- | --- | --- | -//! | `future::join` | `(Result, Result)` | Wait for all to complete -//! | `future::try_join` | `Result<(T1, T2), E>` | Return on first `Err`, wait for all to complete -//! | `future::select` | `Result` | Return on first value -//! | `future::try_select` | `Result` | Return on first `Ok`, reject on last Err +//! | Name | Return signature | When does it return? | +//! | --- | --- | --- | +//! | [`future::join!`] | `(Result, Result)` | Wait for all to complete +//! | [`future::try_join!`] | `Result<(T1, T2), E>` | Return on first `Err`, wait for all to complete +//! | [`Future::select`] | `Result` | Return on first value +//! | [`Future::try_select`] | `Result` | Return on first `Ok`, reject on last Err +//! +//! [`future::join!`]: macro.join.html +//! [`future::try_join!`]: macro.try_join.html +//! [`Future::select`]: trait.Future.html#method.select +//! [`Future::try_select`]: trait.Future.html#method.try_select #[doc(inline)] pub use async_macros::{join, try_join}; @@ -57,9 +62,6 @@ mod ready; mod timeout; cfg_unstable! { - #[doc(inline)] - pub use async_macros::{select, try_select}; - pub use into_future::IntoFuture; mod into_future; } From 99ffed4af73943a30dc0c42577078effbe1139c7 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Mon, 28 Oct 2019 18:31:26 +0100 Subject: [PATCH 02/10] implement Future::select Signed-off-by: Yoshua Wuyts --- src/future/{future.rs => future/mod.rs} | 14 +++++-- src/future/future/select.rs | 54 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 4 deletions(-) rename src/future/{future.rs => future/mod.rs} (96%) create mode 100644 src/future/future/select.rs diff --git a/src/future/future.rs b/src/future/future/mod.rs similarity index 96% rename from src/future/future.rs rename to src/future/future/mod.rs index 4b8360686..23e56f965 100644 --- a/src/future/future.rs +++ b/src/future/future/mod.rs @@ -1,8 +1,10 @@ cfg_unstable! { mod delay; + mod select; use std::time::Duration; + use select::Select; use delay::DelayFuture; } @@ -147,9 +149,9 @@ extension_trait! { # Examples ``` - #![feature(async_await)] # futures::executor::block_on(async { - use futures::future; + use async_std::prelude::*; + use async_std::future; let a = future::pending(); let b = future::ready(1u8); @@ -160,8 +162,12 @@ extension_trait! { # }); ``` "#] - fn select(&mut self) -> () { - () + fn select(self, other: F) -> Select + where + Self: Sized, + F: Future, + { + Select::new(self, other) } } diff --git a/src/future/future/select.rs b/src/future/future/select.rs new file mode 100644 index 000000000..ab8d9d9ad --- /dev/null +++ b/src/future/future/select.rs @@ -0,0 +1,54 @@ +use std::pin::Pin; + +use pin_project_lite::pin_project; +use async_macros::MaybeDone; + +use crate::future::Future; +// use crate::future::MaybeDone; +use crate::task::{Context, Poll}; + +pin_project! { + #[allow(missing_docs)] + #[allow(missing_debug_implementations)] + pub struct Select where L: Future, R: Future { + #[pin] left: MaybeDone, + #[pin] right: MaybeDone, + } +} + +impl Select +where + L: Future, + R: Future, +{ + pub(crate) fn new(left: L, right: R) -> Self { + Self { + left: MaybeDone::new(left), + right: MaybeDone::new(right), + } + } +} + +impl Future for Select +where + L: Future, + R: Future, +{ + type Output = L::Output; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + let this = self.project(); + + let mut left = this.left; + if Future::poll(Pin::new(&mut left), cx).is_ready() { + return Poll::Ready(left.take().unwrap()); + } + + let mut right = this.right; + if Future::poll(Pin::new(&mut right), cx).is_ready() { + return Poll::Ready(right.take().unwrap()); + } + + Poll::Pending + } +} From 9964696db06a2f43cb88a19574505ad829d2482c Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Mon, 28 Oct 2019 20:59:07 +0100 Subject: [PATCH 03/10] try_select Signed-off-by: Yoshua Wuyts --- src/future/future/mod.rs | 51 +++++++++++++++++++++++--- src/future/future/select.rs | 3 +- src/future/future/try_select.rs | 63 +++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 src/future/future/try_select.rs diff --git a/src/future/future/mod.rs b/src/future/future/mod.rs index 23e56f965..517d2add3 100644 --- a/src/future/future/mod.rs +++ b/src/future/future/mod.rs @@ -1,11 +1,13 @@ cfg_unstable! { mod delay; mod select; + mod try_select; use std::time::Duration; - use select::Select; use delay::DelayFuture; + use select::Select; + use try_select::TrySelect; } extension_trait! { @@ -133,7 +135,7 @@ extension_trait! { } #[doc = r#" - Waits for either one of several similarly-typed futures to complete. + Waits for one of two similarly-typed futures to complete. Awaits multiple futures simultaneously, returning all results once complete. @@ -149,7 +151,7 @@ extension_trait! { # Examples ``` - # futures::executor::block_on(async { + # async_std::task::block_on(async { use async_std::prelude::*; use async_std::future; @@ -162,12 +164,51 @@ extension_trait! { # }); ``` "#] - fn select(self, other: F) -> Select + fn select(self, other: F) -> + impl Future [Select] + where + Self: Sized + Future, + F: std::future::Future::Output>, + { + Select::new(self, other) + } + + #[doc = r#" + Waits for one of two similarly-typed fallible futures to complete. + + Awaits multiple futures simultaneously, returning all results once complete. + + `try_select` is similar to [`select`], but keeps going if a future + resolved to an error until all futures have been resolved. In which case + the error of the `other` future will be returned. + + # Examples + + ``` + # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + # + use async_std::prelude::*; + use async_std::future; + use std::io::{Error, ErrorKind}; + + let a = future::pending::>(); + let b = future::ready(Err(Error::from(ErrorKind::Other))); + let c = future::ready(Ok(1u8)); + + let f = a.try_select(b).try_select(c); + assert_eq!(f.await?, 1u8); + # + # Ok(()) }) } + ``` + "#] + fn try_select(self, other: F) -> + impl Future [TrySelect] where Self: Sized, + Self: Future>, F: Future, { - Select::new(self, other) + TrySelect::new(self, other) } } diff --git a/src/future/future/select.rs b/src/future/future/select.rs index ab8d9d9ad..6fe2ebf11 100644 --- a/src/future/future/select.rs +++ b/src/future/future/select.rs @@ -3,8 +3,7 @@ use std::pin::Pin; use pin_project_lite::pin_project; use async_macros::MaybeDone; -use crate::future::Future; -// use crate::future::MaybeDone; +use std::future::Future; use crate::task::{Context, Poll}; pin_project! { diff --git a/src/future/future/try_select.rs b/src/future/future/try_select.rs new file mode 100644 index 000000000..ce307be79 --- /dev/null +++ b/src/future/future/try_select.rs @@ -0,0 +1,63 @@ +use std::pin::Pin; + +use async_macros::MaybeDone; +use pin_project_lite::pin_project; + +use std::future::Future; +use crate::task::{Context, Poll}; + +pin_project! { + #[allow(missing_docs)] + #[allow(missing_debug_implementations)] + pub struct TrySelect where L: Future, R: Future { + #[pin] left: MaybeDone, + #[pin] right: MaybeDone, + } +} + +impl TrySelect +where + L: Future, + R: Future, +{ + pub(crate) fn new(left: L, right: R) -> Self { + Self { + left: MaybeDone::new(left), + right: MaybeDone::new(right), + } + } +} + +impl Future for TrySelect +where + L: Future>, + R: Future, +{ + type Output = L::Output; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + let this = self.project(); + let mut left_errored = false; + + // Check if the left future is ready & successful. Continue if not. + let mut left = this.left; + if Future::poll(Pin::new(&mut left), cx).is_ready() { + if left.as_ref().output().unwrap().is_ok() { + return Poll::Ready(left.take().unwrap()); + } else { + left_errored = true; + } + } + + // Check if the right future is ready & successful. Return err if left + // future also resolved to err. Continue if not. + let mut right = this.right; + if Future::poll(Pin::new(&mut right), cx).is_ready() { + if right.as_ref().output().unwrap().is_ok() || left_errored { + return Poll::Ready(right.take().unwrap()); + } + } + + Poll::Pending + } +} From 14e39b3349e678377c426bccc91e3ab6fcf6076e Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Mon, 28 Oct 2019 21:00:56 +0100 Subject: [PATCH 04/10] fixes Signed-off-by: Yoshua Wuyts --- src/future/future/mod.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/future/future/mod.rs b/src/future/future/mod.rs index 517d2add3..f0185f758 100644 --- a/src/future/future/mod.rs +++ b/src/future/future/mod.rs @@ -164,11 +164,13 @@ extension_trait! { # }); ``` "#] + #[cfg(any(feature = "unstable", feature = "docs"))] + #[cfg_attr(feature = "docs", doc(cfg(unstable)))] fn select(self, other: F) -> - impl Future [Select] - where - Self: Sized + Future, - F: std::future::Future::Output>, + impl Future [Select] + where + Self: Sized + Future, + F: std::future::Future::Output>, { Select::new(self, other) } @@ -201,12 +203,14 @@ extension_trait! { # Ok(()) }) } ``` "#] + #[cfg(any(feature = "unstable", feature = "docs"))] + #[cfg_attr(feature = "docs", doc(cfg(unstable)))] fn try_select(self, other: F) -> - impl Future [TrySelect] - where - Self: Sized, - Self: Future>, - F: Future, + impl Future [TrySelect] + where + Self: Sized, + Self: Future>, + F: Future, { TrySelect::new(self, other) } From 48217830702fcb18302ed02ebe3293edb6ea343c Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Tue, 29 Oct 2019 00:22:41 +0100 Subject: [PATCH 05/10] works Signed-off-by: Yoshua Wuyts --- src/future/future/mod.rs | 21 ++++++++++++--------- src/utils.rs | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/future/future/mod.rs b/src/future/future/mod.rs index f0185f758..c46a05763 100644 --- a/src/future/future/mod.rs +++ b/src/future/future/mod.rs @@ -166,11 +166,13 @@ extension_trait! { "#] #[cfg(any(feature = "unstable", feature = "docs"))] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - fn select(self, other: F) -> - impl Future [Select] + fn select( + self, + other: F + ) -> impl Future::Output> [Select] where - Self: Sized + Future, - F: std::future::Future::Output>, + Self: std::future::Future + Sized, + F: std::future::Future::Output>, { Select::new(self, other) } @@ -205,12 +207,13 @@ extension_trait! { "#] #[cfg(any(feature = "unstable", feature = "docs"))] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - fn try_select(self, other: F) -> - impl Future [TrySelect] + fn try_select( + self, + other: F + ) -> impl Future::Output> [TrySelect] where - Self: Sized, - Self: Future>, - F: Future, + Self: std::future::Future> + Sized, + F: std::future::Future::Output>, { TrySelect::new(self, other) } diff --git a/src/utils.rs b/src/utils.rs index 60516d257..75c379975 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -144,7 +144,7 @@ macro_rules! extension_trait { }; // Parse the return type in an extension method. - (@doc ($($head:tt)*) -> impl Future [$f:ty] $($tail:tt)*) => { + (@doc ($($head:tt)*) -> impl Future $(+ $lt:lifetime)? [$f:ty] $($tail:tt)*) => { extension_trait!(@doc ($($head)* -> owned::ImplFuture<$out>) $($tail)*); }; (@ext ($($head:tt)*) -> impl Future $(+ $lt:lifetime)? [$f:ty] $($tail:tt)*) => { From 311c32ae39060e1049e79090662e19b382da9631 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Tue, 29 Oct 2019 00:29:12 +0100 Subject: [PATCH 06/10] pass clippy Signed-off-by: Yoshua Wuyts --- src/future/future/try_select.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/future/future/try_select.rs b/src/future/future/try_select.rs index ce307be79..d9ed7654d 100644 --- a/src/future/future/try_select.rs +++ b/src/future/future/try_select.rs @@ -53,7 +53,9 @@ where // future also resolved to err. Continue if not. let mut right = this.right; if Future::poll(Pin::new(&mut right), cx).is_ready() { - if right.as_ref().output().unwrap().is_ok() || left_errored { + if right.as_ref().output().unwrap().is_ok() { + return Poll::Ready(right.take().unwrap()); + } else if left_errored { return Poll::Ready(right.take().unwrap()); } } From c04b35c0adda02d3e92ba7880f4810918759c6c2 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Tue, 29 Oct 2019 02:19:14 +0100 Subject: [PATCH 07/10] please clippy Signed-off-by: Yoshua Wuyts --- src/future/future/try_select.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/future/future/try_select.rs b/src/future/future/try_select.rs index d9ed7654d..93609692b 100644 --- a/src/future/future/try_select.rs +++ b/src/future/future/try_select.rs @@ -3,8 +3,8 @@ use std::pin::Pin; use async_macros::MaybeDone; use pin_project_lite::pin_project; -use std::future::Future; use crate::task::{Context, Poll}; +use std::future::Future; pin_project! { #[allow(missing_docs)] @@ -52,12 +52,9 @@ where // Check if the right future is ready & successful. Return err if left // future also resolved to err. Continue if not. let mut right = this.right; - if Future::poll(Pin::new(&mut right), cx).is_ready() { - if right.as_ref().output().unwrap().is_ok() { - return Poll::Ready(right.take().unwrap()); - } else if left_errored { - return Poll::Ready(right.take().unwrap()); - } + let is_ready = Future::poll(Pin::new(&mut right), cx).is_ready(); + if is_ready && (right.as_ref().output().unwrap().is_ok() || left_errored) { + return Poll::Ready(right.take().unwrap()); } Poll::Pending From ebe29ac2ae7546ef798e60fb9a378c52280922e8 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Tue, 29 Oct 2019 19:53:07 +0100 Subject: [PATCH 08/10] implement feedback from stjepan Signed-off-by: Yoshua Wuyts --- src/future/future/mod.rs | 8 ++++++-- src/future/future/select.rs | 10 +++++++--- src/future/future/try_select.rs | 6 +++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/future/future/mod.rs b/src/future/future/mod.rs index c46a05763..d67b4a2a1 100644 --- a/src/future/future/mod.rs +++ b/src/future/future/mod.rs @@ -137,7 +137,8 @@ extension_trait! { #[doc = r#" Waits for one of two similarly-typed futures to complete. - Awaits multiple futures simultaneously, returning all results once complete. + Awaits multiple futures simultaneously, returning the output of the + first future that completes. This function will return a new future which awaits for either one of both futures to complete. If multiple futures are completed at the same time, @@ -184,7 +185,10 @@ extension_trait! { `try_select` is similar to [`select`], but keeps going if a future resolved to an error until all futures have been resolved. In which case - the error of the `other` future will be returned. + an error is returned. + + The ordering of which value is yielded when two futures resolve + simultaneously is intentionally left unspecified. # Examples diff --git a/src/future/future/select.rs b/src/future/future/select.rs index 6fe2ebf11..928595848 100644 --- a/src/future/future/select.rs +++ b/src/future/future/select.rs @@ -1,15 +1,19 @@ use std::pin::Pin; -use pin_project_lite::pin_project; use async_macros::MaybeDone; +use pin_project_lite::pin_project; -use std::future::Future; use crate::task::{Context, Poll}; +use std::future::Future; pin_project! { #[allow(missing_docs)] #[allow(missing_debug_implementations)] - pub struct Select where L: Future, R: Future { + pub struct Select + where + L: Future, + R: Future + { #[pin] left: MaybeDone, #[pin] right: MaybeDone, } diff --git a/src/future/future/try_select.rs b/src/future/future/try_select.rs index 93609692b..f87360dac 100644 --- a/src/future/future/try_select.rs +++ b/src/future/future/try_select.rs @@ -9,7 +9,11 @@ use std::future::Future; pin_project! { #[allow(missing_docs)] #[allow(missing_debug_implementations)] - pub struct TrySelect where L: Future, R: Future { + pub struct TrySelect + where + L: Future, + R: Future + { #[pin] left: MaybeDone, #[pin] right: MaybeDone, } From 679da06eef88d62cadd5d154c0fc1a5bea83374b Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 1 Nov 2019 01:49:31 +0100 Subject: [PATCH 09/10] rename select to race Signed-off-by: Yoshua Wuyts --- src/future/future/mod.rs | 26 +++++++++---------- src/future/future/{select.rs => race.rs} | 6 ++--- .../future/{try_select.rs => try_race.rs} | 6 ++--- 3 files changed, 19 insertions(+), 19 deletions(-) rename src/future/future/{select.rs => race.rs} (93%) rename src/future/future/{try_select.rs => try_race.rs} (94%) diff --git a/src/future/future/mod.rs b/src/future/future/mod.rs index d67b4a2a1..dad94daa8 100644 --- a/src/future/future/mod.rs +++ b/src/future/future/mod.rs @@ -1,13 +1,13 @@ cfg_unstable! { mod delay; - mod select; - mod try_select; + mod race; + mod try_race; use std::time::Duration; use delay::DelayFuture; - use select::Select; - use try_select::TrySelect; + use race::Race; + use try_race::TryRace; } extension_trait! { @@ -160,22 +160,22 @@ extension_trait! { let b = future::ready(1u8); let c = future::ready(2u8); - let f = a.select(b).select(c); + let f = a.race(b).race(c); assert_eq!(f.await, 1u8); # }); ``` "#] #[cfg(any(feature = "unstable", feature = "docs"))] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - fn select( + fn race( self, other: F - ) -> impl Future::Output> [Select] + ) -> impl Future::Output> [Race] where Self: std::future::Future + Sized, F: std::future::Future::Output>, { - Select::new(self, other) + Race::new(self, other) } #[doc = r#" @@ -183,7 +183,7 @@ extension_trait! { Awaits multiple futures simultaneously, returning all results once complete. - `try_select` is similar to [`select`], but keeps going if a future + `try_race` is similar to [`race`], but keeps going if a future resolved to an error until all futures have been resolved. In which case an error is returned. @@ -203,7 +203,7 @@ extension_trait! { let b = future::ready(Err(Error::from(ErrorKind::Other))); let c = future::ready(Ok(1u8)); - let f = a.try_select(b).try_select(c); + let f = a.try_race(b).try_race(c); assert_eq!(f.await?, 1u8); # # Ok(()) }) } @@ -211,15 +211,15 @@ extension_trait! { "#] #[cfg(any(feature = "unstable", feature = "docs"))] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - fn try_select( + fn try_race( self, other: F - ) -> impl Future::Output> [TrySelect] + ) -> impl Future::Output> [TryRace] where Self: std::future::Future> + Sized, F: std::future::Future::Output>, { - TrySelect::new(self, other) + TryRace::new(self, other) } } diff --git a/src/future/future/select.rs b/src/future/future/race.rs similarity index 93% rename from src/future/future/select.rs rename to src/future/future/race.rs index 928595848..2fd604a73 100644 --- a/src/future/future/select.rs +++ b/src/future/future/race.rs @@ -9,7 +9,7 @@ use std::future::Future; pin_project! { #[allow(missing_docs)] #[allow(missing_debug_implementations)] - pub struct Select + pub struct Race where L: Future, R: Future @@ -19,7 +19,7 @@ pin_project! { } } -impl Select +impl Race where L: Future, R: Future, @@ -32,7 +32,7 @@ where } } -impl Future for Select +impl Future for Race where L: Future, R: Future, diff --git a/src/future/future/try_select.rs b/src/future/future/try_race.rs similarity index 94% rename from src/future/future/try_select.rs rename to src/future/future/try_race.rs index f87360dac..d0ca4a90f 100644 --- a/src/future/future/try_select.rs +++ b/src/future/future/try_race.rs @@ -9,7 +9,7 @@ use std::future::Future; pin_project! { #[allow(missing_docs)] #[allow(missing_debug_implementations)] - pub struct TrySelect + pub struct TryRace where L: Future, R: Future @@ -19,7 +19,7 @@ pin_project! { } } -impl TrySelect +impl TryRace where L: Future, R: Future, @@ -32,7 +32,7 @@ where } } -impl Future for TrySelect +impl Future for TryRace where L: Future>, R: Future, From 1dc205704b3e1db932db8a3f83552a7d726f328a Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 1 Nov 2019 02:00:57 +0100 Subject: [PATCH 10/10] fmt Signed-off-by: Yoshua Wuyts --- src/future/mod.rs | 16 ++++++++-------- src/stream/stream/min.rs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/future/mod.rs b/src/future/mod.rs index 7789ddee3..dd28f2848 100644 --- a/src/future/mod.rs +++ b/src/future/mod.rs @@ -4,7 +4,7 @@ //! //! Often it's desireable to await multiple futures as if it was a single //! future. The `join` family of operations converts multiple futures into a -//! single future that returns all of their outputs. The `select` family of +//! single future that returns all of their outputs. The `race` family of //! operations converts multiple future into a single future that returns the //! first output. //! @@ -13,7 +13,7 @@ //! | Name | Return signature | When does it return? | //! | --- | --- | --- | //! | [`future::join!`] | `(T1, T2)` | Wait for all to complete -//! | [`Future::select`] | `T` | Return on first value +//! | [`Future::race`] | `T` | Return on first value //! //! ## Fallible Futures Concurrency //! @@ -25,9 +25,9 @@ //! futures are dropped and an error is returned. This is referred to as //! "short-circuiting". //! -//! In the case of `try_select`, instead of returning the first future that +//! In the case of `try_race`, instead of returning the first future that //! completes it returns the first future that _successfully_ completes. This -//! means `try_select` will keep going until any one of the futures returns +//! means `try_race` will keep going until any one of the futures returns //! `Ok`, or _all_ futures have returned `Err`. //! //! However sometimes it can be useful to use the base variants of the macros @@ -38,13 +38,13 @@ //! | --- | --- | --- | //! | [`future::join!`] | `(Result, Result)` | Wait for all to complete //! | [`future::try_join!`] | `Result<(T1, T2), E>` | Return on first `Err`, wait for all to complete -//! | [`Future::select`] | `Result` | Return on first value -//! | [`Future::try_select`] | `Result` | Return on first `Ok`, reject on last Err +//! | [`Future::race`] | `Result` | Return on first value +//! | [`Future::try_race`] | `Result` | Return on first `Ok`, reject on last Err //! //! [`future::join!`]: macro.join.html //! [`future::try_join!`]: macro.try_join.html -//! [`Future::select`]: trait.Future.html#method.select -//! [`Future::try_select`]: trait.Future.html#method.try_select +//! [`Future::race`]: trait.Future.html#method.race +//! [`Future::try_race`]: trait.Future.html#method.try_race #[doc(inline)] pub use async_macros::{join, try_join}; diff --git a/src/stream/stream/min.rs b/src/stream/stream/min.rs index 1ab56065d..b4a8c7c16 100644 --- a/src/stream/stream/min.rs +++ b/src/stream/stream/min.rs @@ -1,5 +1,5 @@ +use std::cmp::{Ord, Ordering}; use std::marker::PhantomData; -use std::cmp::{Ordering, Ord}; use std::pin::Pin; use pin_project_lite::pin_project;