I was trying to follow along with the MDN promise.all example but it seems I cannot pass more arguments to the setTimeout callback.
var p1 = new Promise((resolve, reject) => {
setTimeout(resolve, 200, 1,2,3);
});
var p2 = new Promise((resolve, reject) => {
setTimeout(resolve, 500, "two");
});
Promise.all([p1, p2]).then(value => {
console.log(value);
}, reason => {
console.log(reason)
});
This prints [1, "two"]
, where I would expect [1, 2, 3, "two"]
. Doing this with setTimeout
without promise fulfillment works as expected
setTimeout(cb, 100, 1, 2, 3);
function cb(a, b, c){
console.log(a, b, c);
}
//=>1 2 3
Why doesn't this work with the promise? How can it be made to work with the promise?