Concurrency Limit
Concurrency Limit
Execute promises with a maximum concurrency limit.
Requirements:
- Implement promisePool that takes array of async functions and limit
- Execute at most limit promises concurrently
- When a promise completes, start the next one from the queue
- Return all results in original order
Example:
const tasks = [
async () => 1,
async () => 2,
async () => 3,
async () => 4
];
promisePool(tasks, 2).then(results => {
console.log(results); // [1, 2, 3, 4]
});
Examples:
Input 1:
{"tasks":[null,null,null],"limit":2}Output 1:
[1,2,3]Loading editor...
Run your code to see results
Click the Run button above