Skip to content

Add for_await to process streams using a for loop #2

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

Merged
merged 7 commits into from
Aug 19, 2019
Merged

Add for_await to process streams using a for loop #2

merged 7 commits into from
Aug 19, 2019

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Aug 14, 2019

No description provided.

Copy link
Member Author

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

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

Blocked on #1

@@ -20,7 +20,7 @@ repository = "https://github.com/tokio-rs/async-stream"
readme = "README.md"

[dependencies]
async-stream-impl = { version = "0.1.0" }
async-stream-impl = { version = "0.1.0", path = "../async-stream-impl" }
Copy link
Member Author

Choose a reason for hiding this comment

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

This must be revert before merging.

Copy link
Member

Choose a reason for hiding this comment

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

It's fine to keep the path in here IMO.

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

LGTM 👍 some thoughts inline.

@@ -98,6 +98,42 @@ impl VisitMut for Scrub {
syn::visit_mut::visit_expr_mut(self, i);
self.is_xforming = prev;
}
syn::Expr::ForLoop(expr) => {
syn::visit_mut::visit_expr_for_loop_mut(self, expr);
// TODO: Should we allow other attributes?
Copy link
Member

Choose a reason for hiding this comment

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

What about just #[await]?

Also, since this is a macro anyway, we could potentially get more aggressive and transform:

for await foo in my_stream {
}

Copy link
Member Author

Choose a reason for hiding this comment

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

What about just #[await]?

Sounds good to me.

for await foo in my_stream {
}

I think syn doesn't support this syntax yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

(By the way, that TODO comment is about the current implementation confirming that the number of attributes is exactly one.)

Copy link
Member

Choose a reason for hiding this comment

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

syn doesn't support it... but it may not be too hard to impl. You would have to manually walk the TokenStream and find for followed by await, transform that to #[await] for then run ^^.

That can be follow up work though...

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in c1d4aef

@taiki-e taiki-e marked this pull request as ready for review August 14, 2019 17:40
@carllerche carllerche merged commit 024be65 into tokio-rs:master Aug 19, 2019
@taiki-e taiki-e deleted the for-await branch August 19, 2019 16:22
@taiki-e taiki-e mentioned this pull request Nov 24, 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