From 53a727fe187e496b6962884ba9f8995b154534c5 Mon Sep 17 00:00:00 2001 From: tungli Date: Sun, 14 Feb 2021 17:00:06 +0100 Subject: [PATCH 1/3] small change in `select` example. In the previous example one future always finished first (because of implementation details), possibly confusing users about what `select` does. This commit resolves the issue by being explicit about one future finishing before the other. --- futures-util/src/future/select.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/futures-util/src/future/select.rs b/futures-util/src/future/select.rs index fc4316afa2..fbab9dc5cf 100644 --- a/futures-util/src/future/select.rs +++ b/futures-util/src/future/select.rs @@ -32,12 +32,20 @@ impl Unpin for Select {} /// /// ``` /// # futures::executor::block_on(async { -/// use futures::future::{self, Either}; -/// use futures::pin_mut; -/// -/// // These two futures have different types even though their outputs have the same type -/// let future1 = async { 1 }; -/// let future2 = async { 2 }; +/// use futures::{ +/// pin_mut, +/// future::Either, +/// future::self, +/// }; +/// +/// // These two futures have different types even though their outputs have the same type. +/// let future1 = async { +/// let () = future::pending().await; // will never finish +/// 1 +/// }; +/// let future2 = async { +/// future::ready(2).await +/// }; /// /// // 'select' requires Future + Unpin bounds /// pin_mut!(future1); @@ -45,12 +53,12 @@ impl Unpin for Select {} /// /// let value = match future::select(future1, future2).await { /// Either::Left((value1, _)) => value1, // `value1` is resolved from `future1` -/// // `_` represents `future2` +/// // `_` represents `future2` /// Either::Right((value2, _)) => value2, // `value2` is resolved from `future2` -/// // `_` represents `future1` +/// // `_` represents `future1` /// }; /// -/// assert!(value == 1 || value == 2); +/// assert!(value == 2); /// # }); /// ``` /// From 4c6f7ff7705f8128917e5fbcf2c8326db980d77d Mon Sep 17 00:00:00 2001 From: Jan Tungli <33368331+tungli@users.noreply.github.com> Date: Sun, 14 Feb 2021 18:32:05 +0100 Subject: [PATCH 2/3] Update futures-util/src/future/select.rs Co-authored-by: Taiki Endo --- futures-util/src/future/select.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/futures-util/src/future/select.rs b/futures-util/src/future/select.rs index fbab9dc5cf..069d6f7f5c 100644 --- a/futures-util/src/future/select.rs +++ b/futures-util/src/future/select.rs @@ -40,7 +40,7 @@ impl Unpin for Select {} /// /// // These two futures have different types even though their outputs have the same type. /// let future1 = async { -/// let () = future::pending().await; // will never finish +/// future::pending::<()>().await; // will never finish /// 1 /// }; /// let future2 = async { From ce0e58616c8ae892a2c7688b532be46f0c4f42fe Mon Sep 17 00:00:00 2001 From: Jan Tungli <33368331+tungli@users.noreply.github.com> Date: Sun, 14 Feb 2021 18:34:14 +0100 Subject: [PATCH 3/3] Update select.rs --- futures-util/src/future/select.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/futures-util/src/future/select.rs b/futures-util/src/future/select.rs index 069d6f7f5c..043ed178e7 100644 --- a/futures-util/src/future/select.rs +++ b/futures-util/src/future/select.rs @@ -52,10 +52,10 @@ impl Unpin for Select {} /// pin_mut!(future2); /// /// let value = match future::select(future1, future2).await { -/// Either::Left((value1, _)) => value1, // `value1` is resolved from `future1` -/// // `_` represents `future2` +/// Either::Left((value1, _)) => value1, // `value1` is resolved from `future1` +/// // `_` represents `future2` /// Either::Right((value2, _)) => value2, // `value2` is resolved from `future2` -/// // `_` represents `future1` +/// // `_` represents `future1` /// }; /// /// assert!(value == 2);