-
Notifications
You must be signed in to change notification settings - Fork 86
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
feat: add support for async based resource operation handlers #523
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The callback passed to .end method receives 3 arguments: err, data and meta. Therefore, we don't need to capture meta in the serviceMeta array as we used to do.
- Remove unnecessary setImmediate (since we started using promises, we are not blocking the main thread anymore). - Move _executeRequest to Request class (since it operates quite heavily on the request object). - _executeRequest always resolves now. The resolved object contains an err, data and meta properties. This change allows us to simplify .end and ._captureMetaAndStats methods. - _captureMetaAndStats is simpler now, it takes the err and meta object directly so we don't need to guess if they exist or not.
With this change, it's now possible to use fetchr fully callbackless. If any resource handler is defined with one or less arguments, we expect this resource to be async and we pass all the arguments in just one object to it (which also simplifies the signature of the handlers).
redonkulus
reviewed
Aug 19, 2024
redonkulus
reviewed
Aug 19, 2024
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.
This is great, all backwards compatible right? Tested on a real app?
@redonkulus yes, I tried with npm link on our main website code with both versions running (callback and async). All good! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.
This PR enables fetchr to be used without any callback.
Before
After
It's still possible to use the old signature since we detect the new one based on the number or arguments defined in the handler.
This change also make it simple to create handlers that do not require any argument:
Before
After