Last active
June 17, 2016 21:20
-
-
Save jugglinmike/247c9ef460a86fdbd5778e3a8c581cd9 to your computer and use it in GitHub Desktop.
Promise.all inconsistency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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