then
doesn't take a Promise
as an input, it takes 2 functions, 1 for fulfillment and 1 for rejection.
The reason d
is resolved is due to the fact that calling .then with a non-callable value (even a number literal - 1, or undefined
) causes the onFulfilled function to be replace by "Identity", which simply re-fulfills with whatever value was resolved in the previous step. See PerformPromiseThen
Try like this:
//promises that are never resolved nor rejected
var a = function() { return new Promise(function(r,re){}); };
var b = function() { return new Promise(function(r,re){}); };
var c = function() { return new Promise(function(r,re){}); };
// or simply, a = b = c after setting the function for c
var d = [a, b, c].reduce(function (previousPromise, fn) {
return previousPromise.then(fn, /* not passing a rejection handler... */);
}, Promise.resolve());
Or alternatively...
//promises that are never resolved nor rejected
var a = new Promise(function(r,re){});
var b = new Promise(function(r,re){});
var c = new Promise(function(r,re){});
var d = [a, b, c].reduce(function (previousPromise, promise) {
return previousPromise.then(function() {return promise;});
}, Promise.resolve());
And since you're using promises & ES6, you could be more concise:
let a = new Promise(() => {});
let b = new Promise(() => {});
let c = new Promise(() => {});
let d = [a, b, c].reduce((previousPromise, promise) =>
previousPromise.then(() => promise),
Promise.resolve());