Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/myrotvorets/promise-chunk
Runs a list of native promises in chunks.
https://github.com/myrotvorets/promise-chunk
batch chunk promise
Last synced: 22 days ago
JSON representation
Runs a list of native promises in chunks.
- Host: GitHub
- URL: https://github.com/myrotvorets/promise-chunk
- Owner: myrotvorets
- License: mit
- Created: 2020-10-24T20:19:28.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-12-16T03:07:22.000Z (26 days ago)
- Last Synced: 2024-12-16T20:36:09.615Z (25 days ago)
- Topics: batch, chunk, promise
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@myrotvorets/promise-chunk
- Size: 2.56 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# promise-chunk
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=myrotvorets_promise-chunk&metric=alert_status)](https://sonarcloud.io/dashboard?id=myrotvorets_promise-chunk)
[![Build and Test](https://github.com/myrotvorets/promise-chunk/actions/workflows/build.yml/badge.svg)](https://github.com/myrotvorets/promise-chunk/actions/workflows/build.yml)Runs a list of native promises in chunks.
# Example
```typescript
import promiseChunk from '@myrotvorets/promise-chunk'function* requestGenerator(): Generator>> {
const ids = ['81e', 'a46', 'SQIzfUkYJ', 'JFPROfGtQ', 'g-gQiPV-_'];
for (const id of ids) {
const url = `https://api.thecatapi.com/v1/images/${id}`;
yield fetch(url).then((response) => response.json() as Promise>);
}
}async function getCats(): Promise {
const jsons = await promiseChunk(requestGenerator(), 2);
jsons
.filter((item): item is Record => !(item instanceof Error))
.forEach((cat) => console.log(cat.url));
}getCats().catch((e: unknown) => console.error(e));
```