In production web applications, firing hundreds of concurrent HTTP requests simultaneously can overwhelm browser network pools or hit API rate limits. Building an Async Concurrency Limiter (Task Pool) is a classic senior live coding interview task.
Problem Statement
Write a function mapConcurrent(items, limit, asyncFn) that executes asyncFn for every item in items, ensuring at most limit promises execute concurrently.
Optimal Solution
async function mapConcurrent(items, limit, asyncFn) {
const results = [];for (const [index, item] of items.entries()) { const p = Promise.resolve().then(() => asyncFn(item, index)); results[index] = p; executing.add(p);
const clean = () => executing.delete(p); p.then(clean, clean);
if (executing.size >= limit) { await Promise.race(executing); } }
return Promise.all(results); } ```
---
Try this Problem Live on Pairlet Practice the [Concurrency Limiter coding challenge](https://www.pairlet.dev/problems/concurrency-limiter) live in a collaborative interview session.
Conduct Live Coding Interviews with Zero Friction
No candidate sign-up required. Create an instant room, share the link, and code together in real time with shared code execution.