UNPKG

@lx-frontend/multi-track

Version:

sls 日志上传功能,当前支持小程序、web

31 lines (30 loc) 687 B
/** * @example 并发控制类 * * const concurrent = new Concurrent(3); // 3个并发 * * // 模拟10个异步任务 * for (let i = 0; i < 10; i++) { * concurrent.append(() => { * return new Promise((resolve) => { * console.log(`开始任务 ${i}`) * setTimeout(() => { * console.log(`结束任务 ${i}`) * resolve(true) * }, 1000) * }) * }) * } * */ export declare class Concurrent { /** 并发数量 */ private total; /** 当前并发数量 */ private count; /** 等待执行任务 */ private peddings; constructor(total: number); append(fn: () => Promise<any>): void; private run; }