async-task-throttle
Version:
A simple async task throttle.
20 lines (19 loc) • 636 B
TypeScript
export declare type ITask<R = any> = (...args: any[]) => Promise<R>;
export interface IAsyncTaskOptions {
args: any[];
resolve: (value?: unknown) => void;
reject: (reason?: any) => void;
}
export default class AsyncTaskThrottle<S extends ITask> {
static create<T extends ITask>(task: T, size?: number, max?: number): T;
private _queue;
private _queueLength;
private _workerCount;
private _task;
private _workingCount;
constructor(task: S, workerCount?: number, queueLength?: number);
getWorkingCount(): number;
create(): S;
push(options: IAsyncTaskOptions): void;
private work;
}