mirror of
https://github.com/async-rs/async-std.git
synced 2025-03-05 01:29:43 +00:00
Fixed deduplication of code
This commit is contained in:
parent
5d558ca213
commit
f6829859fe
1 changed files with 22 additions and 18 deletions
|
@ -45,25 +45,29 @@ where
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
let this = self.project();
|
let this = self.project();
|
||||||
if utils::random(1) == 1 {
|
if utils::random(1) == 1 {
|
||||||
match this.left.poll_next(cx) {
|
poll_next_in_order(this.left, this.right, cx)
|
||||||
Poll::Ready(Some(item)) => Poll::Ready(Some(item)),
|
|
||||||
Poll::Ready(None) => this.right.poll_next(cx),
|
|
||||||
Poll::Pending => match this.right.poll_next(cx) {
|
|
||||||
Poll::Ready(Some(item)) => Poll::Ready(Some(item)),
|
|
||||||
Poll::Ready(None) => Poll::Pending,
|
|
||||||
Poll::Pending => Poll::Pending,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
match this.right.poll_next(cx) {
|
poll_next_in_order(this.right, this.left, cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn poll_next_in_order<F, S, I>(
|
||||||
|
first: Pin<&mut F>,
|
||||||
|
second: Pin<&mut S>,
|
||||||
|
cx: &mut Context<'_>,
|
||||||
|
) -> Poll<Option<I>>
|
||||||
|
where
|
||||||
|
F: Stream<Item = I>,
|
||||||
|
S: Stream<Item = I>,
|
||||||
|
{
|
||||||
|
match first.poll_next(cx) {
|
||||||
Poll::Ready(Some(item)) => Poll::Ready(Some(item)),
|
Poll::Ready(Some(item)) => Poll::Ready(Some(item)),
|
||||||
Poll::Ready(None) => this.left.poll_next(cx),
|
Poll::Ready(None) => second.poll_next(cx),
|
||||||
Poll::Pending => match this.left.poll_next(cx) {
|
Poll::Pending => match second.poll_next(cx) {
|
||||||
Poll::Ready(Some(item)) => Poll::Ready(Some(item)),
|
Poll::Ready(Some(item)) => Poll::Ready(Some(item)),
|
||||||
Poll::Ready(None) => Poll::Pending,
|
Poll::Ready(None) => Poll::Pending,
|
||||||
Poll::Pending => Poll::Pending,
|
Poll::Pending => Poll::Pending,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue