Back to Problem Library
Async Control Flow

Implement Concurrency Limiter

hardJS / TS

Problem Statement

Implement a `ConcurrencyLimiter` class (or function) that manages async task execution, ensuring that no more than `maxConcurrency` tasks run simultaneously while queueing additional tasks.

Examples

Example:
const limiter = new ConcurrencyLimiter(2);
limiter.add(() => fetch('/api/1'));
limiter.add(() => fetch('/api/2'));
limiter.add(() => fetch('/api/3')); // Waits until 1 or 2 finishes
Includes TypeScript & JavaScript starter code
Start Interview with this Problem