Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neki-dev/promise-partial
🧩 Partial (mixed) promise execution
https://github.com/neki-dev/promise-partial
async partial promise
Last synced: 2 months ago
JSON representation
🧩 Partial (mixed) promise execution
- Host: GitHub
- URL: https://github.com/neki-dev/promise-partial
- Owner: neki-dev
- License: mit
- Created: 2021-02-06T17:21:04.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-04T22:55:47.000Z (5 months ago)
- Last Synced: 2024-10-11T15:15:19.866Z (3 months ago)
- Topics: async, partial, promise
- Language: TypeScript
- Homepage:
- Size: 257 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## âš¡ Promise partial
[![Version](https://badgen.net/npm/v/promise-partial)](https://npmjs.com/package/promise-partial)
[![Size](https://img.badgesize.io/neki-dev/promise-partial/master/dist/index.js)](https://github.com/neki-dev/promise-partial/blob/master/dist/index.js)
[![Build](https://github.com/neki-dev/promise-partial/actions/workflows/build.yml/badge.svg)](https://github.com/neki-dev/promise-partial/actions/workflows/build.yml)Partial (mixed) promise execution
.
![Partial](https://i.ibb.co/J2ZcvzV/partial.png)
Array is divided on groups by _K_ items. Items in groups is handled in parallel. But groups are called in turn.
```ts
await promisePartial(items, someAsyncFunction, K)
```
.For example - Default methods:
.
![Serial](https://i.ibb.co/n77YP3n/serial.png)
Each item of array is handled one by one. Like a simple `for`
```ts
for (const value of items) {
await someAsyncFunction(value)
}
```.
![Parallel](https://i.ibb.co/hM5RTC5/parallel.png)
Each item of array is handled in parallel. Like a `Promise.all`
```ts
await Promise.all(items.map(someAsyncFunction))
```.
* ### Install
```sh
npm i promise-partial
```* ### Usage
```ts
promisePartial(
// Array of items for map
array: T[],
// Callback for handle of item
callback: (item: T, index: number) => Promise,
// Part size for array dividing
partSize: number
): Promise[]:
```* ### Example
```ts
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);
```