Exercise: An Asynchronous map()

Practice how to implement a parallel asynchronous version of the Array.map() utility.

Problem statement

Implement a parallel asynchronous version of Array.map() that supports promises and a concurrency limit. The function shouldn’t directly leverage the TaskQueue or TaskQueuePC classes but it can use the underlying patterns. The function, which you’ll define as mapAsync(iterable, callback, concurrency), should accept the following as inputs:

  • An iterable, such as an array.

  • A callback, which will receive as the input each item of the iterable (exactly like in the original Array.map()) and can return either a Promise or a simple value.

  • A concurrency, which defines how many items in the iterable can be processed by callback in parallel at each given time.

Coding challenge

Write your solution code in the following code widget. We’ve already added the package.json file for your ease.

Get hands-on with 1400+ tech skills courses.