-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Normative: Add Promise.allSettled() #1583
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
Conversation
spec.html
Outdated
1. Let _values_ be _F_.[[Values]]. | ||
1. Let _promiseCapability_ be _F_.[[Capability]]. | ||
1. Let _remainingElementsCount_ be _F_.[[RemainingElements]]. | ||
1. Let _obj_ be ! ObjectCreate(%ObjectPrototype%). |
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.
would it be worth (for readability) making an abstract operation here (and below) like CreateSettledResult(true/false, x)
?
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.
That sounds like a potentially beneficial refactoring! Would you like this to happen as part of this PR, or separately as a follow-up?
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 guess it could be either, but it’d be nice to do it as part of this PR :-)
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.
it seems with that change we could also fold these two algorithms into one
spec.html
Outdated
1. Assert: ! IsConstructor(_constructor_) is *true*. | ||
1. Assert: _resultCapability_ is a PromiseCapability Record. | ||
1. Let _values_ be a new empty List. | ||
1. Let _remainingElementsCount_ be a new Record { [[Value]]: 1 }. |
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.
Perhaps it would be beneficial to add a note explaining why remainingElementsCount
is a Record rather than just a Number (to pass it by reference rather than by value)?
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 just matches the precedent set by PerformPromiseAll
. I'm not opposed to changing this, but maybe we can do it as a separate PR?
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 find this approach highly distasteful (altho i have no better suggestions atm), and commented such on the proposal repo, but since it does mirror the existing approach i think pursuing changing both in a separate PR is the proper approach (rather than obstructing this proposal).
fcc7642
to
8fbd973
Compare
spec.html
Outdated
1. Let _values_ be _F_.[[Values]]. | ||
1. Let _promiseCapability_ be _F_.[[Capability]]. | ||
1. Let _remainingElementsCount_ be _F_.[[RemainingElements]]. | ||
1. Let _obj_ be ! ObjectCreate(%ObjectPrototype%). |
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.
1. Let _obj_ be ! ObjectCreate(%ObjectPrototype%). | |
1. Let _obj_ be ! ObjectCreate(%Object.prototype%). |
spec.html
Outdated
1. Let _values_ be _F_.[[Values]]. | ||
1. Let _promiseCapability_ be _F_.[[Capability]]. | ||
1. Let _remainingElementsCount_ be _F_.[[RemainingElements]]. | ||
1. Let _obj_ be ! ObjectCreate(%ObjectPrototype%). |
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.
1. Let _obj_ be ! ObjectCreate(%ObjectPrototype%). | |
1. Let _obj_ be ! ObjectCreate(%Object.prototype%). |
Is anything still blocking this? It seems we can apply @chicoxyzzy's suggestions and (given that both @ljharb and @zenparsing LGTM'd) get this merged? |
Note that @jasonwilliams somehow cannot apply the open suggestions: Perhaps one of the editors can take care of this before merging? |
@mathiasbynens that's a github bug, i believe when the suggester and the PR author both have write access - but either way it can be applied manually on the command line. I can certainly incorporate any open suggestions prior to merging as well. |
Okay, so this seems good to go then! |
8fbd973
to
6744202
Compare
... in recently-merged `allSettled` (tc39#1583)
This is a pull request for the Stage 3 proposal https://github.com/tc39/proposal-promise-allSettled. The proposal is championed by @mathiasbynens.
test262 tests: yes tc39/test262#2131 and tc39/test262#2124
Rationale
A common use case for this combinator is wanting to take an action after multiple requests have completed, regardless of their success or failure. Other Promise combinators can short-circuit, discarding the results of input values that lose the race to reach a certain state. Promise.allSettled is unique in always waiting for all of its input values.