@push.rocks/lik
Version:
Provides a collection of lightweight helpers and utilities for Node.js projects.
33 lines (32 loc) • 1.49 kB
TypeScript
export declare class AsyncExecutionStack {
private executionSlots;
private isProcessing;
/** Maximum concurrent non-exclusive tasks (Infinity = unlimited) */
private nonExclusiveMaxConcurrency;
/** Currently running non-exclusive task count */
private nonExclusiveCurrentCount;
/** Queue of resolvers waiting for a non-exclusive slot */
private nonExclusivePendingQueue;
getExclusiveExecutionSlot<T = any>(funcArg: () => Promise<T>, timeoutArg?: number): Promise<T>;
getNonExclusiveExecutionSlot<T = any>(funcArg: () => Promise<T>, timeoutArg?: number): Promise<T>;
/**
* Set the maximum number of concurrent non-exclusive tasks.
* @param concurrency minimum 1 (Infinity means unlimited)
*/
setNonExclusiveMaxConcurrency(concurrency: number): void;
/** Get the configured max concurrency for non-exclusive tasks */
getNonExclusiveMaxConcurrency(): number;
/** Number of non-exclusive tasks currently running */
getActiveNonExclusiveCount(): number;
/** Number of non-exclusive tasks waiting for a free slot */
getPendingNonExclusiveCount(): number;
private processExecutionSlots;
private executeExclusiveSlot;
private executeNonExclusiveSlots;
/**
* Wait until a non-exclusive slot is available (respects max concurrency).
*/
private waitForNonExclusiveSlot;
/** Release a non-exclusive slot and wake the next waiter, if any. */
private releaseNonExclusiveSlot;
}