Skip to content

promise-chunk 2.0.0

Install from the command line:
Learn more about npm packages
$ npm install @myrotvorets/promise-chunk@2.0.0
Install via package.json:
"@myrotvorets/promise-chunk": "2.0.0"

About this version

promise-chunk

Quality Gate Status Build and Test

Runs a list of native promises in chunks.

Example

import promiseChunk from '@myrotvorets/promise-chunk'

function* requestGenerator(): Generator<Promise<Record<string, unknown>>> {
    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);
    jsons
        .filter((item): item is Record<string, unknown> => !(item instanceof Error))
        .forEach((cat) => console.log(cat.url));
}

getCats().catch((e: unknown) => console.error(e));

Details


Assets

  • promise-chunk-2.0.0.tgz

Download activity

  • Total downloads 0
  • Last 30 days 0
  • Last week 0
  • Today 0