← All Exercises

Async Pool Executor

advancedjavascript~35min

Background

Concurrency pools are essential for rate-limited API calls, batch processing, and avoiding resource exhaustion.

Problem

Write a function that takes a concurrency limit and an array of promise-returning functions, executing them with at most `limit` concurrent runs.

Input

A concurrency limit number and an array of functions returning Promises.

Output

A Promise resolving to an array of results in the same order as the input functions.

Sample tests

Sample 1

Input: limit=2, [fn1, fn2, fn3, fn4]
Expected: [r1, r2, r3, r4]

Your solution

Learning objective

Master concurrent async execution, worker pool patterns, and race condition prevention.