tc39 / proposal-promise-any

ECMAScript proposal: Promise.any
https://tc39.es/proposal-promise-any/
200 stars 27 forks source link

Inaccurate text: we don't always reject with an array of rejection reasons #61

Closed marjakh closed 4 years ago

marjakh commented 4 years ago

Text:

The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.

This is inaccurate; when an error is thrown while iterating the Promises, we don't reject with an "array of rejection reasons" (meaning AggregateError?), we reject with the individual error.

These "more fundamental failures" occur when:

The corrsponding text in Promise.all says:

"The all function returns a new promise which is fulfilled with an array of fulfillment values for the passed promises, or rejects with the reason of the first passed promise that rejects. "

This is also not fully accurate, but we can interpret it permissively to mean that the fundamental failures are equal to the rejection of the corresponding Promise which we were iterating when the failure occurred.

However, this kind of permissive interpretation is harder with the text of Promise.any which says explicitly that it rejects with an array of errors.

marjakh commented 4 years ago

See also https://github.com/tc39/ecma262/issues/1983 for Promise.all

mathiasbynens commented 4 years ago

I've updated the README, but given https://github.com/tc39/ecma262/issues/1983#issuecomment-625284399 I'm not sure if there's anything to be done in terms of the description in the spec text. cc @bakkot

ljharb commented 4 years ago

I agree. The readme is fine with your clarification, altho imo it doesn't add much, since it seems obvious to me that const o = {}; Promise.any({ [Symbol.iterator]() { throw o; } }).catch((e) => { assert(e === o); }) would hold.

marjakh commented 4 years ago

Yea, this is subtle (subtler than other cases where the error cases don't follow what the spec says), but I don't think we should modify the text either.