Promise Chain Not Waiting For Promises To Resolve Before Ending
I've tried to simplify these down a bit: passData.savedDBGames.forEach((gameInfo) => { return new Promise((resolve, reject) => { stats.getPlayersStats
Solution 1:
You seem to reference an undefined variable data2
when building your array playerStatsPromise
. Instead use map
to build your array, since that will return the promises:
var playerStatsPromise = passData.savedDBGames.map((gameInfo) => {
returnnewPromise((resolve, reject) => {
stats.getPlayersStats(gameInfo.fixtureID).then((playerStats) => {
console.info('Grab Done');
resolve();
});
});
});
Promise.all(playerStatsPromise)
.then(function () {
console.info('All Done');
app.io.emit('admin', 'Admin: done');
resolve(passData);
});
And if this is all you do in your first code block, you could simplify to:
var playerStatsPromise = passData.savedDBGames
.map(gameInfo => stats.getPlayersStats(gameInfo.fixtureID));
Promise.all(playerStatsPromise)
.then(function () {
console.info('All Done');
app.io.emit('admin', 'Admin: done');
resolve(passData);
});
Post a Comment for "Promise Chain Not Waiting For Promises To Resolve Before Ending"