Search⌘ K
AI Features

Exercise: An Asynchronous map()

Explore how to implement an asynchronous map function for arrays that supports promises and concurrency limits. Understand how to process iterable elements in parallel without relying directly on TaskQueue classes. This lesson guides you through creating a mapAsync function that manages concurrency, handles promise results, and deals with errors efficiently using asynchronous control flow patterns.

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. ...