Skip to content
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

Add zip and enumerate #9

Closed
wants to merge 4 commits into from
Closed

Add zip and enumerate #9

wants to merge 4 commits into from

Conversation

leshow
Copy link

@leshow leshow commented Mar 22, 2020

add zip/enumerate. Are these implementations okay? I can add a few more if you're good with these

#2

Comment on lines 41 to 49
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = self.project();
let next = ready!(this.stream.poll_next(cx));
let other_next = ready!(this.other.poll_next(cx));
match (next, other_next) {
(Some(a), Some(b)) => Poll::Ready(Some((a, b))),
_ => Poll::Ready(None),
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will drop items when this.stream is ready but this.other is not. In this case, I suggest you store the result of this.stream.poll_next(cx) and use that stored value during the next poll (see here).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, good point.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A straightforward port of the above into ParallelStream requires the ParallelStream::Items to be Sync. I'm not quite sure why, I think because they aren't Fused?

@leshow leshow closed this Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants