1.1.0 • Published 11 months ago

promise-partial v1.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
11 months ago

⚡ 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);
1.1.0

11 months ago

1.0.15

2 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.12

3 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago