Exercise: An Asynchronous map()
Practice how to implement a parallel asynchronous version of the Array.map() utility.
We'll cover the following
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 originalArray.map()
) and can return either aPromise
or a simple value.A
concurrency
, which defines how many items in the iterable can be processed bycallback
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.