para-limit
Limit parallel promises without wrapping your function.
Very tiny lib, easy to use.
Example
const paraLimit = require('para-limit')
const guard = paraLimit(3)
let total = 0
const task = async () => {
total++
return new Promise(resolve => setTimeout(resolve, 1000))
}
Array.from({ length: 100 }).map(async () => {
await guard.acquire() // here
await task()
guard.release() // and here
})
setInterval(() => console.log(total), 1000)
You will see total
added by 3 every second.