para-limit

1.0.2 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i para-limit

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

1.11 kB

Total Files

3

Last publish

Collaborators

  • bonboru93