I am trying to create an array of Promises which would print a message to the console when fulfilled. However, it seems to only print once even though there are 10 promise objects within the array.
I have tried the solution in ES6 Promises/calling a function after multiple promises are fulfilled (can't use Promises.all) but it still does not work.
function fillArrayWithPromise(promise, numTimes) {
let promiseArr = Array(numTimes).fill(promise);
console.log(promiseArr.join("-"));
return promiseArr
}
var sendStuffB = new Promise(
function(resolve, reject) {
try {
console.log("submitted one req");
} catch (error) {
console.log("Error: " + error);
}
}
)
let testA = fillArrayWithPromise(sendStuffB, 10);
Promise.all(
testA.map(promise => Promise.resolve(promise).catch(err => console.log(error)))
).then(function() {
console.log("End");
});
I expected the console to print 10 times of "One object sent" but it is only printed to the console once and continues to run indefinitely afterwards.
Here is the error log: Running Test Script... One object sent submitted one req [object Promise]-[object Promise]-[object Promise]-[object Promise]-[object Promise]-[object Promise]-[object Promise]-[object Promise]-[object Promise]-[object Promise]