archives

« Bugzilla Issues Index

#2980 — Promise.race behavior with empty Iterable is surprising


I discovered this behavior as I was writing a test suite for ES6 promises.

Promise.race([]) returns a Promise which is pending and will reliably never settle.

Furthermore, Promise.race(iterable) is legal, where iterable is some object which satisfies the Iterable interface. The risk I am concerned about is that at runtime, the iterator will be empty, and neither the onFulfilled nor onRejected functions will ever be called, and that this behavior will be difficult for the programmer to identify.

My initial suggestion would have been to make Promise.race() behave as if TypeError had been thrown, and cause the steps in IfAbruptRejectPromise to be followed, leaving the resulting promise in a rejected state.

However, I note that @domenic writes "Regarding Promise.race([]), this has been discussed extensively. It is required for consistency and is not a bug."
see https://github.com/getify/native-promise-only/pull/20#issuecomment-45457923

Therefore my suggestion is merely to modify the ES6 spec to explicitly note that Promise.race([]) creates a pending promise that will never settle, and that this behavior is by design.

Thanks to @rwaldron for asking me to file this issue, see https://github.com/getify/native-promise-only/pull/20#issuecomment-45457586


fixed in rev26 editor's draft

added a note


fixed in rev26