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

impl Stream on Subscription and tweak built-in next() method to align #601

Merged
merged 7 commits into from
Dec 10, 2021

Conversation

jsdw
Copy link
Collaborator

@jsdw jsdw commented Dec 10, 2021

Adds a Stream impl on the Subscription type, and tweaks the type signatuer of the built-in next() method to be identical (and make it use the Stream impl).

Really, the only reason to have a built-in next() method now is to avoid needing to import StreamExt, but I think that's a perfectly good reason to keep it, and if the type sig is identical it hopefully won't lead to much confusion :)

@jsdw jsdw requested a review from a team as a code owner December 10, 2021 15:50
type Item = Result<Notif, Error>;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Option<Self::Item>> {
let n = futures_util::ready!(self.notifs_rx.poll_next_unpin(cx));
let res = n.and_then(|n| match serde_json::from_value::<NotifResponse<Notif>>(n) {
Copy link
Member

Choose a reason for hiding this comment

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

does map work here?

I don't mind but clippy doesn't like and_then here...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ooh good point! I thought I needed and_then but then didn't realise that I then surrounded all of the result arms in Some :)

Copy link
Contributor

@maciejhirsz maciejhirsz left a comment

Choose a reason for hiding this comment

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

Nice, looks pretty clean too!

@jsdw jsdw merged commit b22eb3f into master Dec 10, 2021
@jsdw jsdw deleted the jsdw-subscription-stream branch December 10, 2021 16:40
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.

3 participants