Skip to content

Commit a28ceaa

Browse files
committed
Removed unused future combinators.
1 parent 9078de5 commit a28ceaa

File tree

4 files changed

+4
-120
lines changed

4 files changed

+4
-120
lines changed

swimos_utilities/swimos_future/src/combinators/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub use immediate_or::{
2828
immediate_or_join, immediate_or_start, ImmediateOrJoin, ImmediateOrStart, SecondaryResult,
2929
};
3030

31-
pub use race::{race, race3, Either3, Race2, Race3};
31+
pub use race::{race, Race2};
3232

3333
/// A stream that runs another stream of [`Result`]s until it produces an error and then
3434
/// terminates.

swimos_utilities/swimos_future/src/combinators/race/mod.rs

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -59,94 +59,3 @@ where
5959
Poll::Pending
6060
}
6161
}
62-
63-
#[must_use = "futures do nothing unless you `.await` or poll them"]
64-
#[derive(Debug)]
65-
pub struct Race3<L, M, R> {
66-
left: L,
67-
middle: M,
68-
right: R,
69-
}
70-
71-
impl<L, M, R> Unpin for Race3<L, M, R>
72-
where
73-
L: Unpin,
74-
M: Unpin,
75-
R: Unpin,
76-
{
77-
}
78-
79-
/// Waits for either one of three differently-typed futures to complete and then discards the other
80-
/// future. If all futures are ready then the left future's output is returned.
81-
///
82-
/// This function differs to Future's Select functionality where it discards the remaining futures.
83-
///
84-
/// # Cancel safety
85-
/// This function is not cancellation safe. If a future makes progress and another completes first,
86-
/// then the data may be lost in the pending future. If cancellation safety is required, then
87-
/// future's select may be more appropriate.
88-
pub fn race3<L, M, R>(left: L, middle: M, right: R) -> Race3<L, M, R>
89-
where
90-
L: Future + Unpin,
91-
R: Future + Unpin,
92-
{
93-
Race3 {
94-
left,
95-
middle,
96-
right,
97-
}
98-
}
99-
100-
pub enum Either3<L, M, R> {
101-
Left(L),
102-
Middle(M),
103-
Right(R),
104-
}
105-
106-
impl<L, M, R> Either3<L, M, R> {
107-
/// Return true if the value is the left variant.
108-
pub fn is_left(&self) -> bool {
109-
matches!(self, Either3::Left(_))
110-
}
111-
112-
/// Return true if the value is the middle variant.
113-
pub fn is_middle(&self) -> bool {
114-
matches!(self, Either3::Middle(_))
115-
}
116-
117-
/// Return true if the value is the right variant.
118-
pub fn is_right(&self) -> bool {
119-
matches!(self, Either3::Right(_))
120-
}
121-
}
122-
123-
impl<L, M, R> Future for Race3<L, M, R>
124-
where
125-
L: Future + Unpin,
126-
M: Future + Unpin,
127-
R: Future + Unpin,
128-
{
129-
type Output = Either3<L::Output, M::Output, R::Output>;
130-
131-
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
132-
let Race3 {
133-
left,
134-
middle,
135-
right,
136-
} = self.as_mut().get_mut();
137-
138-
if let Poll::Ready(output) = left.poll_unpin(cx) {
139-
return Poll::Ready(Either3::Left(output));
140-
}
141-
142-
if let Poll::Ready(output) = middle.poll_unpin(cx) {
143-
return Poll::Ready(Either3::Middle(output));
144-
}
145-
146-
if let Poll::Ready(output) = right.poll_unpin(cx) {
147-
return Poll::Ready(Either3::Right(output));
148-
}
149-
150-
Poll::Pending
151-
}
152-
}
Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::combinators::{race, race3, Either3};
1+
use crate::combinators::race;
22
use futures::future::{pending, ready};
33
use futures::FutureExt;
44

@@ -16,28 +16,3 @@ async fn race2_test() {
1616
let both_ready = race(ready(()), ready(())).await;
1717
assert!(both_ready.is_left());
1818
}
19-
20-
#[tokio::test]
21-
async fn race3_test() {
22-
let left_ready = race3(ready(()), pending::<()>(), pending::<()>()).await;
23-
assert!(left_ready.is_left());
24-
25-
let middle_ready = race3(pending::<()>(), ready(()), pending::<()>()).await;
26-
assert!(middle_ready.is_middle());
27-
28-
let right_ready = race3(pending::<()>(), pending::<()>(), ready(())).await;
29-
assert!(right_ready.is_right());
30-
31-
let all_pending = race3(pending::<()>(), pending::<()>(), pending::<()>());
32-
assert!(all_pending.now_or_never().is_none());
33-
34-
let both_ready = race3(ready(()), ready(()), ready(())).await;
35-
assert!(both_ready.is_left());
36-
}
37-
38-
#[test]
39-
fn either_three() {
40-
assert!(Either3::<(), (), ()>::Left(()).is_left());
41-
assert!(Either3::<(), (), ()>::Middle(()).is_middle());
42-
assert!(Either3::<(), (), ()>::Right(()).is_right());
43-
}

swimos_utilities/swimos_future/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ mod retry_strategy;
1717
mod union;
1818

1919
pub use combinators::{
20-
immediate_or_join, immediate_or_start, race, race3, try_last, Either3, ImmediateOrJoin,
21-
ImmediateOrStart, NotifyOnBlocked, Race2, Race3, SecondaryResult, StopAfterError,
20+
immediate_or_join, immediate_or_start, race, try_last, ImmediateOrJoin, ImmediateOrStart,
21+
NotifyOnBlocked, Race2, SecondaryResult, StopAfterError,
2222
};
2323
pub use retry_strategy::{ExponentialStrategy, IntervalStrategy, Quantity, RetryStrategy};
2424
pub use union::{UnionFuture3, UnionFuture4};

0 commit comments

Comments
 (0)