doyle-concurrency-control
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

轻量,兼容TS,可控 Promise 并发数量的 npm 包

安装

npm i doyle-concurrency-control

功能简述

可以用来控制 Promise 的并发数量

应用场景

可以限制请求的并发数

使用示例

import ConcurrencyControl from "doyle-concurrency-control";
const promiseReqArray = [
    () => { return fetch("/api/example1"); },
    // ...
    () => fetch("/api/exampleN")
];
// 自定义最大并发 2
ConcurrencyControl(promiseReqArray, 2).then((res) => {
    // res: Array<{ res: any, status: 'fulfilled' | 'reject' }>
    console.log(res);
});

// 默认最大并发 3
ConcurrencyControl(promiseReqArray).then((res) => {
    // res: Array<{ res: any, status: 'fulfilled' | 'reject' }>
    console.log(res);
});

Alt text

Alt text

Package Sidebar

Install

npm i doyle-concurrency-control

Weekly Downloads

3

Version

1.1.0

License

MIT

Unpacked Size

11.5 kB

Total Files

4

Last publish

Collaborators

  • doylerichard