🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@rsoram/pp-limit

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rsoram/pp-limit

Parallel Promise Limiter (pp-limit) 是一个 Promise 并发控制器,可以控制同时进行的任务数量。

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

pp-limit

Parallel Promise Limiter (pp-limit) 是一个 Promise 并发控制器,可以控制同时进行的任务数量。

使用

初始化

// 允许同时运行 5 个任务的并行控制器
const ppl = new PPLimiter(5);

add - 添加任务

add 函数返回的 Promise 可视作输入的 Promise

const ppl = new PPLimiter(5);
ppl
  .add(() => new Promise((resolve) => resolve(1)))
  .then((result) => console.log(`${result} == 1`)); // 1 == 1

Example: 并发控制

const ppl = new PPLimiter(5);
const tasks = Array.from(
  { length: 20 },
  (_, i) => () => new Promise((resolve) => resolve(i)),
);
await Promise.all(tasks.map((t) => ppl.add(t)));

FAQs

Package last updated on 21 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts