# batch-perform-promise

> batch perform promise

Latest version **5.0.0** (published 2023-07-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install batch-perform-promise
pnpm add batch-perform-promise
yarn add batch-perform-promise
bun add batch-perform-promise
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2023-07-04 |
| First published | 2020-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 84.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | z-hnan |

## Links

- npm: https://www.npmjs.com/package/batch-perform-promise
- Repository: https://github.com/Z-HNAN/batch-perform-promise
- Homepage: https://github.com/Z-HNAN/batch-perform-promise#readme
- Issues: https://github.com/Z-HNAN/batch-perform-promise/issues
- npm.io page: https://npm.io/package/batch-perform-promise

## Dependencies (1)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.22.5

## Recent versions

- 5.0.0 (latest) — 2023-07-04
- 5.0.0-beta.2 — 2023-07-04
- 4.0.1 — 2023-06-29
- 4.0.1-beta.7 — 2023-06-29
- 4.0.1-beta.6 — 2023-06-29
- 4.0.1-beta.5 — 2023-06-29
- 4.0.1-beta.4 — 2023-06-29
- 4.0.1-beta.3 — 2023-06-29
- 4.0.1-beta.2 — 2023-06-28
- 4.0.1-beta.1 — 2023-06-28
- 4.0.1-beta.0 — 2023-06-28
- 3.0.0 — 2021-09-24
- 2.1.0 — 2020-09-05
- 2.0.0 — 2020-08-30
- 1.0.0 — 2020-08-30

## README

# batch-perform-promise

> 5.0版本使用father打包+semaphore实现

批量执行promise的方法，能够自定义“并行”发出的promise的个数

> 并行: promise发出等待时，为并行等待，由于js单线程，发出多个promise时是同步执行的，等待为并行，整体上有一种并行执行promise的感觉


## 快速启动

### 并行发出任务

```ts
import { batchPerformPromise } from 'batch-perform-promise';

// 准备任务以及处理函数
const payloads = ['p1', 'p2', 'p3'];
const handler = async (value: string) => Promise.resolve(value)

// await方式异步调用
const tasks = await batchPerformPromise<string>(payloads, handler);

// 查看调用结果 task
tasks[0] === {
  done: true,
  error: null,
  payload: 'p1',
  success: true,
}
```

### 并行执行时间

```ts
import { batchPerformPromise } from 'batch-perform-promise';

// 准备任务以及处理函数
const payloads = ['p1', 'p2', 'p3', 'p4', 'p5'];
// 处理函数，每2000ms执行完成一个promise
const handler = (payload: string) => new Promise((resolve) => {
  const timer = setTimeout(() => {
    clearTimeout(timer);
    resolve(payload);
  }, 2000);
});

// await方式异步调用
await batchPerformPromise<string>(payloads, handler);

// 一共执行时间6s
// [p1, p2] 2s
// [p3, p4] 2s
// [p5,   ] 2s
//  共计6s
```

更多使用方式参考test文件

---
_Source: https://npm.io/package/batch-perform-promise · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
