Hey Daniel and thank you for an interesting article!
Martin Lichstam
1

In my example, each iteration of the loop waits on the previous promise to complete — since this is a serial map, where we’d expect the function to be run once per element, in order, rather than in parallel.

If you just run:

for (let item of collection) {
promise = fn(item).then(result => results.push(result));
}

It’s not waiting on the previous promise for each iteration, which essentially means it’s going to call the function multiple times in parallel for each item in the array.

That’s fine if you want a parallel map() — but not if you want things to run in series.

Show your support

Clapping shows how much you appreciated Daniel Brain’s story.