1.0.15 • Published 1 year ago

promise-partial v1.0.15

Weekly downloads
4
License
MIT
Repository
github
Last release
1 year ago

⚡ Promise partial

Npm package version Small size Building

Partial (mixed) promise execution

.

Partial

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

await promisePartial(items, someAsyncFunction, K)

.

For example - other 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 = 1000
): Promise<D>[]:
  • Example

const promisePartial = require('promise-partial');

const res = await promisePartial([1, 2, 3, /* and more items */], async (v) => {
    return new Promise((resolve) => {
        // some async process
        setTimeout(() => resolve(v * 2), 100);
    });
});
1.0.15

1 year ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.12

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago