I've tried to simplify these down a bit:
passData.savedDBGames.forEach((gameInfo) => {
return new Promise((resolve, reject) => {
stats.getPlayersStats(gameInfo.fixtureID).then((playerStats) => {
playerStatsPromise.push(playerStats);
console.info('Grab Done');
resolve();
});
});
});
Promise.all(playerStatsPromise)
.then(function () {
console.info('All Done');
app.io.emit('admin', 'Admin: done');
resolve(passData);
});
To my understanding Promise.all
should wait until all of the promises contained in playerStatsPromise
have resolved?
So why does All Done
finish before Grab Done
?