https://github.com/capaj/batched-promise-all
a small utility for awaiting lots of promises easily
https://github.com/capaj/batched-promise-all
Last synced: about 1 year ago
JSON representation
a small utility for awaiting lots of promises easily
- Host: GitHub
- URL: https://github.com/capaj/batched-promise-all
- Owner: capaj
- License: mit
- Created: 2020-07-09T19:07:15.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T19:58:35.000Z (over 3 years ago)
- Last Synced: 2025-02-14T18:38:26.863Z (over 1 year ago)
- Language: TypeScript
- Size: 1.49 MB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# batched-promise-all
:flight_departure: zero deps utility for keeping your memory footprint manageable with varying datasets
## Get started
```
yarn add batched-promise-all
npm i batched-promise-all
```
### Usage
```ts
import { batchedPromiseAll } from 'batched-promise-all'
const array = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
const r = await batchedPromiseAll(
// this will be 4x slower and consume 1/4 of memory compared to the Promise.all(array.map(...))
array,
async (item, index) => {
// your iterator callback-same as you would use for .map method on your array
await delay()
return [item, index]
},
2 // batch size
)
```
### Why would you use this?
When dealing with big data sets awaiting thousands of promises at once can easily make your node.js process run out of memory-especially if you're running on small instances. Using batched-promise-all you can avoid this easily with a single import.