Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
Last active June 17, 2016 21:20
Show Gist options
  • Save jugglinmike/247c9ef460a86fdbd5778e3a8c581cd9 to your computer and use it in GitHub Desktop.
Save jugglinmike/247c9ef460a86fdbd5778e3a8c581cd9 to your computer and use it in GitHub Desktop.
Promise.all inconsistency
var first;
var P = function(executor) {
if (!first) {
return new Promise(executor);
}
first = false;
return new Promise(function(_, reject) {
executor(function() { throw 1; }, reject);
});
};
P.resolve = Promise.resolve;
first = true;
Promise.all.call(P, []) // this promise is rejected
.then(print.bind(null, 'resolve1'), print.bind(null, 'reject1'));
first = true;
Promise.all.call(P, [1]) // this promise is never settled
.then(print.bind(null, 'resolve2'), print.bind(null, 'reject2'));
// Consistent result:
// reject1 1
// reject2 1
// Actual result (and in accordance with latest specification):
// reject1 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment