p-all-limit
TypeScript icon, indicating that this package has built-in type declarations

0.9.3 • Public • Published

p-all-limit

import { promiseAllLimit } from 'p-all-limit'

promiseAllLimit(
  [1, 2, 3, 4],
  async (n) => {
    console.log(n)
    await sleep(1000)
  },
  2
)

outputs:

1
2
# first batch finishes after 1000ms
3
4
# second batch finishes

Why is it needed

For when you are constrained by either memory or some other external constraint(eg. database connections) you must ensure that an array too big won't consume all available resources.

Why yet another package?

There is a lot of similar packages, for example:

but none of them had the API I wished for, also typescript types were lacking for most of these. For example p-limit of them forces you to create a limit function and call it for each promise. This package lets you just call the

Package Sidebar

Install

npm i p-all-limit

Weekly Downloads

135

Version

0.9.3

License

MIT

Unpacked Size

7.63 kB

Total Files

7

Last publish

Collaborators

  • capaj