Skip to content

Commit

Permalink
Update README and fix ESLint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Sep 4, 2024
1 parent f57ea44 commit 9915a09
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
tag-version-prefix=
sign-git-tag=true
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![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)
[![codebeat badge](https://codebeat.co/badges/65aa8710-9d42-4160-8164-eb2b43255820)](https://codebeat.co/projects/github-com-myrotvorets-promise-chunk-master)

Runs a list of native promises in chunks.

Expand All @@ -12,19 +11,19 @@ Runs a list of native promises in chunks.
import promiseChunk from '@myrotvorets/promise-chunk'

function* requestGenerator(): Generator<Promise<Record<string, unknown>>> {
const ids = ['81e', 'a46', 'SQIzfUkYJ', 'JFPROfGtQ', 'g-gQiPV-_']
for (let id of ids) {
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<Record<string, unknown>>);
}
}

async function getCats(): Promise<void> {
const jsons = await promiseChunk(requestGenerator, 2);
const jsons = await promiseChunk(requestGenerator(), 2);
jsons
.filter((item): item is Record<string, unknown> => !(item instanceof Error))
.forEach((cat) => console.log(cat.url));
}

getCats().catch((e) => console.error(e));
getCats().catch((e: unknown) => console.error(e));
```
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-await-in-loop, sonarjs/void-use */
/* eslint-disable no-await-in-loop */

export default async function promiseChunk<T>(
iterable: Iterable<Promise<T>>,
Expand Down

0 comments on commit 9915a09

Please sign in to comment.