-
Notifications
You must be signed in to change notification settings - Fork 88
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
Async-closures or reference-parameterized-closures-returning-futures #78
Comments
@stuhood thanks for the example! I'd love to see a write-up dramatizing and spelling out some of the downsides of this macro approach you ended up with. |
I can provide my own story. It's more of a saga, but contains two examples of this in two different projects. I would consider myself to be an Alan at the time, but it's a tale that involves a few other characters like Alan and Barbara. I will use real names and references, and once it's all written down we can trim it down and extract a persona story out of it. David was using the gotham web framework for some toy projects since before async/await became stable. He was new to rust, and not using it professionally, but had a friend with experience contributing to the compiler that could help him. Gotham's examples were generally clear and well tested, and David enjoyed contributing to them, to show other people how to use the framework. Once async/await became stable, David contributed some examples of how to use async functions to handle http requests (gotham-rs/gotham#281 - first drafted in October 2018 on nightly, "finished" Feb 2020 and merged June 2020 after a maintainership change. This uncovered some ergonomics problems around boxing futures, so a helper method was added in the same PR, but that's unrelated to this ticket). Since Gotham's API predates async functions, it historically required you to take ownership of the request context ( In mid May, someone predictably raised a bug about Eventually, towards the end of June, someone found a forum reply by Alice explaining how to express what the Gotham team were after (higher order lifetimes and helper traits). This was picked up by the gotham team and merged in gotham-rs/gotham#450 . In parallel with this, David helped the Goose team with a proof-of-concept port their http load testing tool to use async, tag1consulting/goose#8 but again ran out of steam before completing the work. The Goose team had a couple of shots at this, and problems storing the callback closure which borrowed some context ( I can write this up as a proper story PR if you want. I guess I'd want to boil the essence down to a single story involving an interaction between Alan and Barbara? |
Brief summary
Not having async closures can mean needing to resort to macros to create certain (fairly common) types of combinators (ones where a closure that returns a future runs into lifetime issues).
We experienced this in pantsbuild/pants#11548, and I ended up writing a macro to put what would have been a parameter to a closure-returning-a-future or async-closure directly on the stack instead: pantsbuild/pants#11759
Optional details
The text was updated successfully, but these errors were encountered: