Control async work in the browser: limit how many tasks run at once, share one token refresh across many failing requests, choose between Promise.all, allSettled, race, and any, and add timeouts. Then build a concurrency limiter.
JavaScript runs your code on one thread, but async work overlaps: dozens of requests, uploads, and timers can be in flight at once. Most frontend concurrency bugs come from not controlling that overlap:
Promise.all(files.map(upload)) opens 200 requests. Browsers allow only about 6 HTTP/1.1 connections per host, the rest queue invisibly, the page's own API calls get stuck behind them, and a rate-limited API starts returning 429s.Promise.all. One slow, failing widget blanks the whole page.The tools for all of these are small and composable:
| Problem | Tool |
|---|---|
| Too much at once | A concurrency limiter (a queue with N slots) |
| Duplicated work | Single-flight: share one in-flight promise |
| All-or-nothing | Promise.allSettled and per-item error states |
| Unbounded waiting | Timeouts with Promise.race or AbortSignal.timeout() |
| Wasted work | Cancellation with AbortController |