Six errands, and the market serves at most three at once: send them one by one, all together, in batches, or as a pool of N runners, with real timers timing…
Why it matters
Uploading hundreds of files, calling an API for every table row, fetching a gallery’s images: without a concurrency limit the server refuses or the browser chokes; with rigid batches your time goes waiting for the slowest. A pool (like p-limit) is the pattern.
The key idea
A pool keeps N going; a batch waits for its slowest
Common mistakes
Using Promise.all for hundreds of requests, the server answers 429Promise.all limits nothing: every request leaves when map runs. Use a pool of N runners (or p-limit) so at most N are out.
Thinking a pool runs as rigid batches A batch waits for its slowest before setting off again; a pool fills a free place at once. With uneven times, a pool is always faster.
One task rejects and the whole batch fails, though the rest succeededPromise.all gives up at the first rejection. Use Promise.allSettled (or a .catch per task) to keep every result, then deal with the failed ones yourself.
Try it in this playground
Watch the market answer 429 Open All at once.
A pool runner takes the next ticket at once Open A pool of runners and step through.
The next batch waits for the slowest Open In batches until the second batch sets off.
Promise.all gives up, runners keep walking Open Out of tomatoes and run until the last runner is back.