JavaScript · Senior · Question 23 of 75
How do you limit the number of concurrent requests when loading 100 URLs?
- ✓Correct answer: A pool: N "workers" take URLs from a shared queue until it's empty
- 2
Promise.allitself limits concurrency to six requests - 3Start the requests via
setTimeoutwith a delay of 0
Explanation
Promise.all starts everything at once and has no limit (the browser's connection limit concerns the network, not memory or the server). A pool of N async functions pulling tasks from a queue keeps exactly N requests in flight. Ready-made implementations: p-limit and similar.