Promises with a concurrency limit

A code exercise of about 20 minutes: read the statement, solve «Promises with a concurrency limit» in the browser and get a review like in a real interview.

Code · 20 min
Loading…

Statement

Write mapLimit(items, limit, fn): call the async function fn with each item, with at most limit calls in flight, and return the results in the same order as items. If a call fails, the returned promise rejects with that error. Useful to call an external API without flooding it (e.g. when migrating 50,000 products). In the explanation, say how you wait when limit calls are already in flight.