-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: conform to handler function signature #10
Conversation
src/lib/builder_functions.js
Outdated
|
||
return augmentResponse(response) | ||
if (execution instanceof Promise) { |
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.
@erezrokah Is this what you had in mind in b3a1933#r47416097?
I wonder if this check should be (execution instanceof Promise || execution.then !== undefined)
? Or even (execution !== undefined)
, because if you're returning something from the handler it probably means you're not using the callback syntax.
When it's unclear, I think we should lean towards treating it as an asynchronous handler since the callback syntax is now considered legacy.
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.
Yes exactly - we could use https://github.com/then/is-promise to make it work with non native promise libs like http://bluebirdjs.com/.
I can see someone returning a value from a callback based pattern by mistake...
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.
Done in ed0e801.
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.
feel free to disregard my comment
|
||
return augmentResponse(response) | ||
if (isPromise(execution)) { |
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.
I'm not sure if we should return execution
if this is not a promise just for the sake of keeping the original function behavior.
Very much and edge case of someone returning a value from a callback based pattern
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.
Done in 570d001.
I'm all for keeping this wrapper as little intrusive as possible, so this makes perfect sense to me. Thanks!
Which problem is this pull request solving?
This PR changes the signature of the wrapped function to only be a Promise if the wrapped method is also a Promise. The goal is to provide a better support for the legacy callback syntax.
Checklist
Please add a
x
inside each checkbox: