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

Implications of adopting async await with es7 #420

Closed
calebboyd opened this issue Mar 6, 2015 · 4 comments
Closed

Implications of adopting async await with es7 #420

calebboyd opened this issue Mar 6, 2015 · 4 comments

Comments

@calebboyd
Copy link

It's looking like koa might adopt async awaitsyntax coming in es7. And its implementation (specifically the way middleware are composed) raises some questions.

As the proposal stands, the async modifier is set indicating the function returns a Promise; explicitly or by awaiting one, then returning a value.

My question comes from the observation that next is not a promise -- how then, can it be await-ed?
Supposing it were a promise. The nature of it being named next implies that the upstream has already occurred which should not be true until after await next.

A solution would be to alter the api such that middleware must invoke next() which imo gives more control to whoever is implementing the middleware

I could be completely wrong and perhaps not understand the direction koa is going. Is koa going to stick with generators? It would seem the api is designed specifically for them.

@jonathanong
Copy link
Member

#415

if you look at https://github.com/thenables/composition, it is done by simply adding a .then() function to next, making it a "lazy promise".

@calebboyd
Copy link
Author

My feedback and questions received no reply in #415 :/. I looked at composition and that raised the second question/statement

Supposing it were a promise. The nature of it being named next implies that the upstream has already occurred which should not be true until after await next.

I guess I'm saying it is non-intuitive that it does indeed call the upstream of the next middleware

@jonathanong
Copy link
Member

¯\_(ツ)_/¯ this is the path we've chosen. i guess it is confusing if you're coming from promise-land, not generator-land

@calebboyd
Copy link
Author

Sounds good

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

No branches or pull requests

2 participants