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

Which fix removes the inefficiency?

async function loadAll(ids) {
  const out = [];
  for (const id of ids) {
    out.push(await fetchOne(id));
  }
  return out;
}
  1. Run them together with Promise.all(map)
  2. Run them together with Promise.any(map)
  3. Remove the await from inside the loop
  4. Change the for...of into a forEach
Awaiting inside the loop serialises the requests; Promise.all runs them in parallel.
Play Problem Solving ▸