Skip to content

Rate Limiter Problem

You are given an array of URLs: ['url1', 'url2', ...] and a limit on the number of simultaneous requests - limit.

Implement a function that queries the URLs and invokes a callback with an array of responses: ['url1_answer', 'url2_answer', ...] such that at any given time, no more than limit requests are executed concurrently. As soon as one request completes, the next one should be initiated.

In other words, you need to implement a request queue with a width equal to limit.

Requirements:

function parallelLimit(urls, limit, callback) {
  // your code here
}