UNPKG

minimal-promise-pool

Version:

A minimal library for managing multiple promise instances (promise pool).

36 lines (35 loc) 1.38 kB
export declare class PromisePool<T = unknown> { private readonly promises; private readonly resumeFunctions; private resumeFunctionIndex; private reservedPromiseCount; private _concurrency; private _queuedPromiseCount; constructor(concurrency?: number); get workingPromiseCount(): number; get concurrency(): number; set concurrency(concurrency: number); get queuedPromiseCount(): number; promiseAll(): Promise<T[]>; promiseAllSettled(): Promise<PromiseSettledResult<T>[]>; run(startPromise: () => Promise<T>): Promise<void>; runAndWaitForReturnValue<R extends T>(startPromise: () => Promise<R>): Promise<R>; private runQueued; private runQueuedAndWaitForReturnValue; /** * Starts the given task using a slot the caller has already reserved. * The reservation is converted into a working promise, or released if `startPromise` throws. */ private startReservedTask; private tryReserveCapacity; private waitForResume; /** * Decides whether the slot reserved by resume() can be kept, releasing it otherwise. * The check happens after a microtask hop so that a concurrency reduction applied * right after resume() can still cancel stale reservations. */ private tryKeepReservedSlot; private completeTask; private resume; private hasCapacity; }