promise-partial
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

⚡ Promise partial

Version Size Build

Partial (mixed) promise execution

.

Partial

Array is divided on groups by K items. Items in groups is handled in parallel. But groups are called in turn.

await promisePartial(items, someAsyncFunction, K)

.

For example - Default methods:

.

Serial

Each item of array is handled one by one. Like a simple for

for (const value of items) {
    await someAsyncFunction(value)
}

.

Parallel

Each item of array is handled in parallel. Like a Promise.all

await Promise.all(items.map(someAsyncFunction))

.

  • Install

npm i promise-partial
  • Usage

promisePartial<T, D>(
    // Array of items for map
    array: T[],
    // Callback for handle of item
    callback: (item: T, index: number) => Promise<D>,
    // Part size for array dividing
    partSize: number
): Promise<D>[]:
  • Example

import promisePartial from 'promise-partial';

const items = [1, 2, 3, /* and more items */];
const partSize = 2;

const result = await promisePartial(items, async (value) => {
    return new Promise((resolve) => {
        // some async process
        setTimeout(() => resolve(value * 2), 100);
    });
}, partSize);

/promise-partial/

    Package Sidebar

    Install

    npm i promise-partial

    Weekly Downloads

    14

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    6.41 kB

    Total Files

    11

    Last publish

    Collaborators

    • neki-development