Member-only story
Array.fromAsync Runs Your Async Work One at a Time
It looks like Promise.all over map, but the mapper waits for each result. Here is when that helps and when it hurts.
Ferid Brković
7 min read6 hours ago
Press enter or click to view image in full size
Array.fromAsync(ids, loadPrice) reads like the modern way to write Promise.all(ids.map(loadPrice)) . Same inputs, same array of results, in the same order, with less punctuation.
It is not the same call. With a mapper, Array.fromAsync waits for each result before it asks for the next one. Five requests of 50 ms each take about 250 ms instead of about 50, and nothing in the output tells you.
The same result, five times slower
To see what happens you need to count, not just time. The helper below stands in for a network call.…