-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Feature/async parse args experiment #1913
Closed
shadowspawn
wants to merge
12
commits into
tj:develop
from
shadowspawn:feature/async-parseArgs-experiment
Closed
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7171bfa
Add _settleOptionPromises and call before preAction hook
shadowspawn d3eb58e
Add _settleOptionPromises in _dispatchSubcommand
shadowspawn 80f475e
Call _settleOptionPromises when no action handler
shadowspawn 6b7cee7
Add custom error handling for async Option.parseArgs
shadowspawn e03456b
Add comment
shadowspawn 750b513
Add _settleArgumentPromises
shadowspawn 30dcb28
Add support for resolving previous value before calling parseArgs
shadowspawn d243325
Return updated promise after adding catch, and add catch using then()
shadowspawn 3504504
Fix promise collection
shadowspawn a3c4cd3
Add local catch for promise
shadowspawn 6fd35d2
Replace forEach
shadowspawn c06d412
Return boolean from thenable()
shadowspawn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
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.
refineError()
throws, so there will be an unhandled promise rejection. The result of thecatch()
call needs to be assigned toresult
to prevent it.But if
previous
is already thenable, it is better to callcatch()
in theprevious.then()
callback (and return the result). Otherwise,catch()
might be called on an already failed promise chain in which an error has already been caught and rethrown (because that is whatrefineError()
does), sorefineError()
would be called again which does not make sense.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.
Also, I think calling
result.then(x => x, refineError)
instead ofresult.catch(refineError)
is more robust.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.
Oops, yes, good catch.
I think this is correct pattern, but I'll try it before explaining my reasoning.
Because we only test for
.then()
? Yes, I have thought about that in past and then forgot. I want to just assume they are promise-like since the primary use-case is for async, but it isn't hard to only rely onthen
and cover a few more edge uses.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.
Took me a while to understand this. I was expecting a long catch chain, but see it can be avoided. 👍