Skip to content

Commit

Permalink
join should yield item immediately if either stream is ready
Browse files Browse the repository at this point in the history
If one of the streams is ready and the other is pending, we should
just return the item from the ready stream. Otherwise, join will never
resolve until both streams are ready (which could be never).

Fixes #12.
  • Loading branch information
zeenix committed Dec 27, 2022
1 parent 1ac2385 commit cee7062
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ where
// If one side is pending, we can't return Ready until that gets resolved. Because we
// have already requested that our child streams wake us when it is possible to make
// any kind of progress, we meet the requirements to return Poll::Pending.
(PollState::Item(a, t), PollState::Pending) => {
*this.state = JoinState::A(a, t);
Poll::Pending
}
(PollState::Pending, PollState::Item(b, t)) => {
*this.state = JoinState::B(b, t);
Poll::Pending
}
(PollState::Item(a, t), PollState::Pending) => Poll::Ready(PollResult::Item {
data: a,
ordering: t,
}),
(PollState::Pending, PollState::Item(b, t)) => Poll::Ready(PollResult::Item {
data: b,
ordering: t,
}),
(PollState::Pending, PollState::Pending) => Poll::Pending,
(PollState::Pending, PollState::NoneBefore) => Poll::Pending,
(PollState::NoneBefore, PollState::Pending) => Poll::Pending,
Expand Down

0 comments on commit cee7062

Please sign in to comment.