-
Notifications
You must be signed in to change notification settings - Fork 147
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
Control passed to handler before completing middleware chain #98
Comments
You need to return a promise if you do asynchronous activities, which includes calling next IIRC (it's been a while since I've worked with Koa). Here's a working example: https://gist.github.com/1f0670e88911cac546dc80548bca1865 |
@PlasmaPower your example does work. I'm struggling to understand why though. This feels like Promise black magic haha. Thoughts on this being an antipattern? My experience with callbacks is that you need to call next before moving on. |
You're probably thinking of the express model. In Koa, you almost always return a promise. |
Expanding on @PlasmaPower's answer: Promises need to be chain returned otherwise any of them will resolve and Koa flushes the response. All next calls return a promise guaranteed because of how compose works - meaning that even if you call next expecting it will be a normal function it's actually a promise. |
Hey, folks --
I feel like I must be doing something silly here, but I'm experiencing an issue where the middleware chain is not completely resolved before my code passes control to the final handler. Let me know if this is something I'm doing or an actual bug, thanks!
Setup:
yield* next
instead ofyield next
#2 - immmediately calls nextExpected Output:
Actual Output:
Code:
The text was updated successfully, but these errors were encountered: