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

1.0.15 • Public • Published

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);
    });
});

Package Sidebar

Install

npm i promise-partial

Weekly Downloads

3

Version

1.0.15

License

MIT

Unpacked Size

6.89 kB

Total Files

10

Last publish

Collaborators

  • neki-development