Which fix removes the bug?
items.forEach(async (item) => {
await save(item);
});
console.log('all saved');
- Use a
for...ofloop instead - Mark the outer scope
async - Move the log inside forEach
- Return the promise from save
forEach ignores the returned promises, so the log fires before any save finishes.
Play Problem Solving ▸