Skip to content

Instantly share code, notes, and snippets.

@getify
Last active May 24, 2018 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getify/bd11ccf1eff2efdac0fb to your computer and use it in GitHub Desktop.
Save getify/bd11ccf1eff2efdac0fb to your computer and use it in GitHub Desktop.
more Promise confusion/inconsistency (or implementation bugs?)
/*
Just an update for posterity:
These bugs have been fixed by implementations and all 6 of these examples
work fine in current Chrome, Firefox, and Safari (checked on May 24, 2018).
*/
Promise.reject(42).then(null,null).then(null,function(reason){
console.log("reason:" + reason);
}); // reason:42
Promise.reject(42).then(5,null).then(null,function(reason){
console.log("reason:" + reason);
}); // reason:42
Promise.reject(42).then(null,5).then(null,function(reason){
console.log("reason:" + reason);
}); // TypeError: number is not a function
// *************
Promise.resolve(42).then(null,null).then(function(msg){
console.log("msg:" + msg);
},null); // msg:42
Promise.resolve(42).then(null,5).then(function(msg){
console.log("msg:" + msg);
},null); // msg:42
Promise.resolve(42).then(5,null).then(function(msg){
console.log("msg:" + msg);
},null); // (nothing printed)
@jakeatoms
Copy link

I think the issue is you're using the answer to the Ultimate Question of Life, the Universe, and Everything.

try a different number :-D

@getify
Copy link
Author

getify commented May 6, 2014

@domenic confirmed all 6 should work, so this reveals bugs in Chrome/v8, which also means node's (v0.11.x, 0.12.x) Promises will be buggy until fixed. There may be other bugs in the browser too, as it doesn't appear that browsers are running the full test-suite against their implementations. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment