-
Notifications
You must be signed in to change notification settings - Fork 460
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
Support Async Middleware #495
Comments
Perhaps Express can add a hook to register a function to wrap middleware, which could be used to automatically wrap the middleware / handers for this and whatever other purposes. The details for how the interaction will be done with routers will need to be hammered out, but a high-level idea is: app.wrap(function (fn) {
return function (req, res, next) {
fn(req, res, next).catch(next)
}
}) This is very high-level thought, but figured I'd start a discussion here from the comment in Express repo to get a feeling of if this could be a solution or not. |
@dougwilson I think at this stage with async/await finally built-in to the platform, it should just become a core express/kraken feature to support promise-based middleware (without even having to opt-in via It sounds like express 5 is stalling pretty hard (which is fine), so our best bet will be to add this support directly into kraken I think. |
Yea, and it should, but there are still unresolved issues on how exactly we should deal with the resolved values, for example, and how to deal with the Bluebird warnings, as another. |
On the kraken side there a few ways to implement this. One place we may want to look at is in |
Another thing we could do is put this monkey-patching script into its own module and just require it in as needed (either in kraken core or as wanted by various teams): |
This goes along with krakenjs/kraken-js#495 and is a proof-of-concept at this point, not really production ready. There are a few potential ways to support promise-based middleware. This is only one of them.
This goes along with krakenjs/kraken-js#495 and is a proof-of-concept at this point, not really production ready. There are a few potential ways to support promise-based middleware. This is only one of them.
We could potentially integrate with this module: |
I'd love to see us patch express/kraken to directly provide support for async functions.
Specifically I want the errors from an async middleware function to automatically get forwarded into the express default error handler.
Here's an example:
Instead we end up wrapping our async middleware with a function like this:
But sometimes we forget them and things still blow up.
We address this with Flow, but we don't need to, we can actually add this directly into the platform with something like this.
The text was updated successfully, but these errors were encountered: