Parallel Limit
Parallel Limit
Execute async tasks in parallel with a concurrency limit and proper error handling.
Requirements:
- Implement
parallelLimitthat takes tasks array and concurrency limit - Execute at most
limittasks concurrently - Collect all results and errors
- Return object with
resultsanderrorsarrays - 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