Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Do not use forEach with async-await

const players = await this.getWinners();

// BAD
await players.forEach(async (player) => {
  await givePrizeToPlayer(player);
});

await sendEmailToAdmin('All prizes awarded');
============================
Ideal way is


for (const player of players) {
  await givePrizeToPlayer(player);
}
Source by gist.github.com #
 
PREVIOUS NEXT
Tagged: #Do #forEach
ADD COMMENT
Topic
Name
5+7 =