Skip to content
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

Merged
merged 3 commits into from
Feb 23, 2021

Conversation

eduardoboucas
Copy link
Member

@eduardoboucas eduardoboucas commented Feb 23, 2021

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:

  • I have read the contribution guidelines.
  • The status checks are successful (continuous integration). Those can be seen below.

@github-actions github-actions bot added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Feb 23, 2021
@eduardoboucas eduardoboucas added type: chore work needed to keep the product and development running smoothly and removed type: feature code contributing to the implementation of a feature and/or user facing functionality labels Feb 23, 2021

return augmentResponse(response)
if (execution instanceof Promise) {
Copy link
Member Author

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.

Copy link
Contributor

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...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ed0e801.

@eduardoboucas eduardoboucas marked this pull request as ready for review February 23, 2021 11:05
@github-actions github-actions bot added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Feb 23, 2021
Copy link
Contributor

@erezrokah erezrokah left a 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)) {
Copy link
Contributor

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

Copy link
Member Author

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!

@eduardoboucas eduardoboucas merged commit 261d4d2 into main Feb 23, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: chore work needed to keep the product and development running smoothly type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants