Promise.all, but with enforced limit on concurrent promises I'm trying to implement parallelLimit() to limit the number of parallel tasks that can be performed at any time. Personally, I'm using this function for limiting the parallel uploads from my code.

const _ = require('lodash');

async function _parallelLimit(tasks, limit) {
  const _tasks = Object.assign([], _.zip(tasks, _.range(tasks.length)));
  const results = [];
  const awaitWorker = async () =&gt; {
    while (_tasks.length &gt; 0) {
      const [task, idx] = _tasks.pop();
      results[idx] = await task();
    }
  };
  await Promise.all(_.range(0, limit).map(awaitWorker));
  return results;
}
You can remove Object.assign as _.zip will eventually give you the required array. 

Also _.range(0, limit) is equivalent to _.range(limit).