Skip to content

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

Merged
merged 1 commit into from
Sep 27, 2019
Merged

Conversation

jasonwilliams
Copy link
Member

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.

@leobalter leobalter added pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. has test262 tests labels Jun 12, 2019
@ljharb ljharb added the proposal This is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4. label Jun 12, 2019
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%).
Copy link
Member

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)?

Copy link
Member

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?

Copy link
Member

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 :-)

Copy link
Member

@devsnek devsnek Jun 26, 2019

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

@ljharb ljharb requested a review from a team June 13, 2019 16:16
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 }.
Copy link
Member

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)?

Copy link
Member

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?

Copy link
Member

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

@ljharb ljharb self-assigned this Jun 26, 2019
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%).
Copy link
Member

@chicoxyzzy chicoxyzzy Sep 11, 2019

Choose a reason for hiding this comment

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

Suggested change
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%).
Copy link
Member

@chicoxyzzy chicoxyzzy Sep 11, 2019

Choose a reason for hiding this comment

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

Suggested change
1. Let _obj_ be ! ObjectCreate(%ObjectPrototype%).
1. Let _obj_ be ! ObjectCreate(%Object.prototype%).

@ljharb ljharb added has stage 4 This PR represents a proposal that has achieved stage 4, and is ready to merge. and removed pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. labels Sep 11, 2019
@mathiasbynens
Copy link
Member

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?

@mathiasbynens
Copy link
Member

Note that @jasonwilliams somehow cannot apply the open suggestions:

Perhaps one of the editors can take care of this before merging?

@ljharb
Copy link
Member

ljharb commented Sep 21, 2019

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

@mathiasbynens
Copy link
Member

Okay, so this seems good to go then!

@ljharb ljharb merged commit 6744202 into tc39:master Sep 27, 2019
ljharb pushed a commit to jmdyck/ecma262 that referenced this pull request Sep 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has stage 4 This PR represents a proposal that has achieved stage 4, and is ready to merge. has test262 tests proposal This is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants