Async Pool (bounded concurrency)
Speechify interview questions · Medium · Coding round · 12 tests
Run N asynchronous tasks with at most limit in
flight at any moment, returning the results in input order.
Interface
mapLimit<T, R>(
items: T[],
limit: number,
fn: (item: T, index: number) => Promise<R>
): Promise<R[]>
Why this matters
This is the single most on-theme question they could ask a Platform candidate.
The /synthesize endpoint in the drill repo does this:
const audio = await Promise.all(chunks.map(synthesize))
Measured peak concurrency from one request: 122 simultaneous calls to the TTS vendor. Ten users would be 1,220. It exhausts connection pools, trips vendor rate limits, and past saturation it is slower, not faster.
Requirements
Run your code with Ctrl+Enter to see results.