@socketsecurity/lib
Version:
Core utilities and infrastructure for Socket.dev security tools
36 lines (35 loc) • 1.09 kB
TypeScript
export declare class PromiseQueue {
private queue;
private running;
private readonly maxConcurrency;
private readonly maxQueueLength;
/**
* Creates a new PromiseQueue
* @param maxConcurrency - Maximum number of promises that can run concurrently
* @param maxQueueLength - Maximum queue size (older tasks are dropped if exceeded)
*/
constructor(maxConcurrency: number, maxQueueLength?: number | undefined);
/**
* Add a task to the queue
* @param fn - Async function to execute
* @returns Promise that resolves with the function's result
*/
add<T>(fn: () => Promise<T>): Promise<T>;
private runNext;
/**
* Wait for all queued and running tasks to complete
*/
onIdle(): Promise<void>;
/**
* Get the number of tasks currently running
*/
get activeCount(): number;
/**
* Get the number of tasks waiting in the queue
*/
get pendingCount(): number;
/**
* Clear all pending tasks from the queue (does not affect running tasks)
*/
clear(): void;
}