/** Type definition for queued request */ export interface QueuedRequest { taskKey: string; key: INPUT; resolve: (result: OUTPUT) => void; reject: (error: any) => void; } /** Performance metrics for the request queue */ export interface RequestQueueMetrics { currentQueueLength: number; maxQueueLengthReached: number; currentConcurrentRequests: number; maxConcurrentRequestsReached: number; } /** * A specialized queue for managing concurrent request limits in the Promise Cacher. * * This class handles: * - Queuing requests when concurrent limits are reached * - Processing queued requests when slots become available * - Tracking queue performance metrics * - Efficient batch processing of multiple requests * * @template INPUT - The type of keys used to identify cache entries * @template OUTPUT - The type of values returned by cached promises */ export declare class RequestQueue { /** Internal queue storage for pending requests */ private queue; /** Set to track currently running concurrent requests */ private concurrentRequests; /** Performance metrics tracking */ private metrics; /** * Gets the current number of queued requests. */ get length(): number; /** * Gets the current queue performance metrics. */ get performanceMetrics(): RequestQueueMetrics; /** * Checks if the queue is empty. */ get isEmpty(): boolean; /** * Adds a request to the queue and returns a promise that resolves when the request is processed. * * @param taskKey - The transformed cache key * @param key - The original input key * @returns Promise that resolves to the cached or freshly fetched value */ enqueue(taskKey: string, key: INPUT): Promise; /** * Processes queued requests when concurrent slots become available. * Returns an array of requests ready for processing. * * @param availableSlots - Number of concurrent slots available for processing * @returns Array of requests to process */ dequeue(availableSlots: number): QueuedRequest[]; /** * Removes all requests from the queue. * This should be called when clearing the cache to prevent memory leaks. */ clear(): void; /** * Gets all queued requests without removing them from the queue. * Useful for debugging or monitoring purposes. */ peek(): ReadonlyArray>; /** * Updates the performance metrics after queue operations. */ private updateMetrics; /** * Resets all performance metrics to their initial state. */ private resetMetrics; /** * Starts tracking a concurrent request. * * @param taskKey - The cache key of the request to track */ startConcurrentRequest(taskKey: string): void; /** * Stops tracking a concurrent request. * * @param taskKey - The cache key of the request to stop tracking */ endConcurrentRequest(taskKey: string): void; /** * Checks if a request is currently being processed. * * @param taskKey - The cache key to check * @returns True if the request is currently being processed */ isConcurrentRequestActive(taskKey: string): boolean; /** * Gets the current number of concurrent requests. */ get currentConcurrentRequests(): number; /** * Checks if the concurrent limit is reached. * * @param maxConcurrent - Maximum number of concurrent requests allowed * @returns True if the limit is reached */ isConcurrentLimitReached(maxConcurrent?: number): boolean; /** * Clears all concurrent request tracking. */ clearConcurrentRequests(): void; /** * Updates concurrent request metrics. */ private updateConcurrentMetrics; }