number of tasks to run concurrently
array of functions that return a promise
Optional
callback: ((value, index) => void)callback is invoked in order of completion
array of return values which are ordered with indices identical to their respective tasks in the input array.
T - The type of the return value of the tasks.
Will throw an error if any of the tasks fail.
const tasks = [
() => new Promise((resolve) => setTimeout(() => resolve('Task A complete'), 2000)),
() => new Promise((resolve) => setTimeout(() => resolve('Task B complete'), 1000)),
() => new Promise((resolve) => setTimeout(() => resolve('Task C complete'), 3000)),
() => new Promise((resolve) => setTimeout(() => resolve('Task D complete'), 4000)),
() => new Promise((resolve) => setTimeout(() => resolve('Task E complete'), 5000)),
]
const results2 = await asyncTasksLimit(2, tasks, (value, index) => {
console.log(`Task ${index} completed with value ${value}`)
})
console.log(results2)
Generated using TypeDoc
Run async tasks in parallel with a limit on the number of concurrent tasks.