-
Notifications
You must be signed in to change notification settings - Fork 10
BREAKING CHANGE: make execPre async and drop callback support #39
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me, though as i have not worked with this much, i was quite confused about isAsync
vs returning a Promise, but now i understand isAsync
means to run it in parallel instead of waiting before calling the next hook. Maybe add some documentation to the isAsync
parameters?
Another question that came up, should next
be deprecated in favor of using Promises?
Also the documentation (just the README?) needs to be updated to reflect this (btw the README contains some acquit:ignore:end
)
PS: if this PR is a WIP, maybe mark it as such?
@@ -28,8 +28,7 @@ Kareem.overwriteResult = function overwriteResult() { | |||
* Execute all "pre" hooks for "name" | |||
* @param {String} name The hook name to execute | |||
* @param {*} context Overwrite the "this" for the hook | |||
* @param {Array|Function} args Optional arguments or directly the callback | |||
* @param {Function} [callback] The callback to call when executing all hooks are finished | |||
* @param {Array|Function} args arguments passed to the pre hooks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, this should still include Function
even though the callback is removed?
Work in progress to make
execPre()
andexecPost()
use async functions where possible to better support Automattic/mongoose#15317. Tested in kareem repo as well as running Mongoose with these changes.Couple of breaking changes in this PR:
next(null, 'new arg')
and the args to the next middleware would get overwritten by 'new arg'.execPre()
next()
calls. If your middleware function does something likenext(); throw new Error('Fail');
, this new logic will treat the middleware function as errored with error 'Fail'. Kareem@2 ignores the 'Fail' error.@hasezoey your feedback would be much appreciated.