Skip to content

Commit

Permalink
rename select to race
Browse files Browse the repository at this point in the history
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
  • Loading branch information
yoshuawuyts committed Nov 1, 2019
1 parent ebe29ac commit 679da06
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
26 changes: 13 additions & 13 deletions src/future/future/mod.rs
Original file line number Diff line number Diff line change
@@ -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! {
Expand Down Expand Up @@ -160,30 +160,30 @@ 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<F>(
fn race<F>(
self,
other: F
) -> impl Future<Output = <Self as std::future::Future>::Output> [Select<Self, F>]
) -> impl Future<Output = <Self as std::future::Future>::Output> [Race<Self, F>]
where
Self: std::future::Future + Sized,
F: std::future::Future<Output = <Self as std::future::Future>::Output>,
{
Select::new(self, other)
Race::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
`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.
Expand All @@ -203,23 +203,23 @@ 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(()) }) }
```
"#]
#[cfg(any(feature = "unstable", feature = "docs"))]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
fn try_select<F: std::future::Future, T, E>(
fn try_race<F: std::future::Future, T, E>(
self,
other: F
) -> impl Future<Output = <Self as std::future::Future>::Output> [TrySelect<Self, F>]
) -> impl Future<Output = <Self as std::future::Future>::Output> [TryRace<Self, F>]
where
Self: std::future::Future<Output = Result<T, E>> + Sized,
F: std::future::Future<Output = <Self as std::future::Future>::Output>,
{
TrySelect::new(self, other)
TryRace::new(self, other)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/future/future/select.rs → src/future/future/race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::future::Future;
pin_project! {
#[allow(missing_docs)]
#[allow(missing_debug_implementations)]
pub struct Select<L, R>
pub struct Race<L, R>
where
L: Future,
R: Future<Output = L::Output>
Expand All @@ -19,7 +19,7 @@ pin_project! {
}
}

impl<L, R> Select<L, R>
impl<L, R> Race<L, R>
where
L: Future,
R: Future<Output = L::Output>,
Expand All @@ -32,7 +32,7 @@ where
}
}

impl<L, R> Future for Select<L, R>
impl<L, R> Future for Race<L, R>
where
L: Future,
R: Future<Output = L::Output>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::future::Future;
pin_project! {
#[allow(missing_docs)]
#[allow(missing_debug_implementations)]
pub struct TrySelect<L, R>
pub struct TryRace<L, R>
where
L: Future,
R: Future<Output = L::Output>
Expand All @@ -19,7 +19,7 @@ pin_project! {
}
}

impl<L, R> TrySelect<L, R>
impl<L, R> TryRace<L, R>
where
L: Future,
R: Future<Output = L::Output>,
Expand All @@ -32,7 +32,7 @@ where
}
}

impl<L, R, T, E> Future for TrySelect<L, R>
impl<L, R, T, E> Future for TryRace<L, R>
where
L: Future<Output = Result<T, E>>,
R: Future<Output = L::Output>,
Expand Down

0 comments on commit 679da06

Please sign in to comment.