Which fix removes the bug?
async function all(ids) {
const out = [];
ids.forEach(async (id) => {
out.push(await load(id));
});
return out;
}
- Use
await Promise.all(ids.map(load)) - Use
await Promise.race(ids.map(load)) - Add
awaitbefore theids.forEachcall - Change
out.pushtoout.concatinside
forEach ignores the async callbacks, so
Play Problem Solving ▸
out is still empty at the return; Promise.all waits.