Skip to main content

Parallel Limit

SENIOR

Parallel Limit

Execute async tasks in parallel with a concurrency limit and proper error handling.

Requirements:

  • Implement parallelLimit that takes tasks array and concurrency limit
  • Execute at most limit tasks concurrently
  • Collect all results and errors
  • Return object with results and errors arrays
  • Continue processing even if some tasks fail

Example:

const tasks = [
  async () => 1,
  async () => { throw new Error('fail'); },
  async () => 3,
  async () => 4
];

parallelLimit(tasks, 2).then(({ results, errors }) => {
  console.log(results); // [1, 3, 4]
  console.log(errors.length); // 1
});

Examples:

Input 1:{"tasks":[null,null,null],"limit":2}
Output 1:{"results":[1,2,3],"errors":[]}

Loading editor...

Run your code to see results

Click the Run button above