Which fix removes the bug?
const results = [];
items.forEach(async (i) => {
results.push(await load(i));
});
console.log(results.length);
- Use a for...of loop
- Await inside forEach
- Return from the callback
- Wrap in Promise.race
forEach ignores the returned promises, so the log runs before anything resolves.