$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #137

Which fix removes the bug?

items.forEach(async (item) => {
  await save(item);
});
console.log('all saved');
  1. Use a for...of loop instead
  2. Mark the outer scope async
  3. Move the log inside forEach
  4. Return the promise from save
forEach ignores the returned promises, so the log fires before any save finishes.
Play Problem Solving ▸