10000 Don't return `PollRecv::Closed` prematurely by seritools · Pull Request #61 · austinjones/postage-rs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Don't return PollRecv::Closed prematurely #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/stream/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ where
{
match first.poll_recv(cx) {
PollRecv::Ready(v) => MergePoll::First(PollRecv::Ready(v)),
PollRecv::Pending => MergePoll::Second(second.poll_recv(cx)),
PollRecv::Pending => MergePoll::Second(match second.poll_recv(cx) {
PollRecv::Closed => PollRecv::Pending,
recv => recv,
}),
PollRecv::Closed => MergePoll::Second(second.poll_recv(cx)),
}
}
Expand Down Expand Up @@ -167,6 +170,24 @@ mod tests {
assert_eq!(PollRecv::Closed, Pin::new(&mut find).poll_recv(&mut cx));
}

#[test]
fn swap_closed_pending() {
let left = from_poll_iter(vec![]);
let right = from_poll_iter(vec![
PollRecv::Ready(1),
PollRecv::Pending,
PollRecv::Ready(2),
]);
let mut find = MergeStream::new(left, right);

let mut cx = Context::empty();

assert_eq!(PollRecv::Ready(1), Pin::new(&mut find).poll_recv(&mut cx));
assert_eq!(PollRecv::Pending, Pin::new(&mut find).poll_recv(&mut cx));
assert_eq!(PollRecv::Ready(2), Pin::new(&mut find).poll_recv(&mut cx));
assert_eq!(PollRecv::Closed, Pin::new(&mut find).poll_recv(&mut cx));
}

#[test]
fn pending_uses_right() {
let left = from_poll_iter(vec![PollRecv::Pending]);
Expand All @@ -188,6 +209,7 @@ mod tests {
let mut cx = Context::empty();

assert_eq!(PollRecv::Ready(1), Pin::new(&mut find).poll_recv(&mut cx));
assert_eq!(PollRecv::Pending, Pin::new(&mut find).poll_recv(&mut cx));
assert_eq!(PollRecv::Closed, Pin::new(&mut find).poll_recv(&mut cx));
}
}
0