hardcodingjavascript~20 min
Concurrency-Limited Task Queue
Objective: Manage async concurrency with a queue, preserving FIFO order and error isolation.
Implement `createQueue(limit)`. `add(task)` takes a function that returns a promise and returns a promise for its result, running at most `limit` tasks at once.
- At most `limit` tasks run concurrently.
- Tasks start in the order they were added.
- add() resolves/rejects with the task's own outcome.
- A failing task does not stop the queue.
JavaScript
⌘/Ctrl + Enter to run tests · Esc then Tab leaves the editor
Output
> Nothing has run yet.
Interview follow-up questions
- How would you add priorities or cancellation?
- How does this compare to p-limit?
- What changes if tasks must be retried on failure?