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 danieldg#12.
  • Loading branch information
zeenix committed Dec 29, 2022
1 parent d979705 commit f161f04
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,16 @@ where
b.into()
}

// 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
}
// If one side is pending, return the ready one. Otherwise we can easily end up in the
// `Pending` state forever.
(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 f161f04

Please sign in to comment.