@delucis/stau
🚦 Run promises with limited concurrency
Installation
npm install --save @delucis/stau
Usage
stau(functions[, limit = 15])
Resolves when all of the functions
have resolved.
-
functions
Type:
Array
of async/Promise-returning functionsThe functions to execute with limited concurrency
-
limit
Type:
Number
Default:15
The maximum number of functions to execute at the same time
Example
const stau = require('@delucis/stau')
const delay = require('delay')
const task = t => async () => {
console.log(`Waiting for: ${t}ms`)
return delay(t)
}
const tasks = [
task(3000),
task(5000),
task(12000)
]
(async function () {
await stau(tasks, 2)
.then(() => console.log('Done waiting!'))
})()
// immediately:
// => Waiting for: 3000ms
// => Waiting for: 5000ms
//
// after 5 seconds:
// => Waiting for: 12000ms
//
// after 17 seconds:
// => Done waiting!