/** * Concurrency Control Utilities * Direct use of p-queue industry-standard concurrency control * * This module provides simplified interfaces to p-queue functionality * while maintaining the same API for backward compatibility. */ import PQueue from 'p-queue'; /** * Execute promises with controlled concurrency limit using p-queue * @param tasks - Array of functions that return promises * @param concurrency - Maximum number of concurrent operations (default: 10) * @returns Promise that resolves to array of results */ export declare function limitedPromiseAll(tasks: (() => Promise)[], concurrency?: number): Promise; /** * Execute promises with controlled concurrency using Promise.allSettled and p-queue * @param tasks - Array of functions that return promises * @param concurrency - Maximum number of concurrent operations (default: 10) * @returns Promise that resolves to array of settled results */ export declare function limitedPromiseAllSettled(tasks: (() => Promise)[], concurrency?: number): Promise[]>; /** * Execute promises with rate limiting using p-queue and intervals * @param tasks - Array of functions that return promises * @param concurrency - Maximum number of concurrent operations (default: 10) * @param delayMs - Minimum delay between batches in milliseconds (default: 100) * @returns Promise that resolves to array of results */ export declare function rateLimitedPromiseAll(tasks: (() => Promise)[], concurrency?: number, delayMs?: number): Promise; /** * Throttle function calls to prevent excessive frequency * @param fn - Function to throttle * @param delayMs - Minimum delay between calls in milliseconds * @returns Throttled function */ export declare function throttle any>(fn: T, delayMs: number): (...args: Parameters) => void; /** * Debounce function calls to prevent excessive frequency * @param fn - Function to debounce * @param delayMs - Delay before invoking the function * @returns Debounced function */ export declare function debounce any>(fn: T, delayMs: number): (...args: Parameters) => void; /** * Semaphore implementation using p-queue * Provides compatible API while using industry-standard queue */ export declare class Semaphore { private queue; private isDestroyed; constructor(permits: number); /** * Acquire a permit * @param timeoutMs - Timeout in milliseconds (default: 30000) * @returns Promise that resolves when permit is acquired */ acquire(timeoutMs?: number): Promise; /** * Release a permit - no-op with p-queue * p-queue manages permits automatically */ release(): void; /** * Get current available permits */ getAvailablePermits(): number; /** * Get queue length */ getQueueLength(): number; /** * Destroy semaphore and reject all waiting requests */ destroy(): void; } /** * Execute function within semaphore context * @param semaphore - Semaphore instance * @param fn - Function to execute * @param timeoutMs - Timeout for acquiring semaphore (default: 30000) * @returns Promise that resolves to function result */ export declare function withSemaphore(semaphore: Semaphore, fn: () => Promise, timeoutMs?: number): Promise; /** * Rolling concurrency with dynamic adjustment * @param tasks - Array of functions that return promises * @param initialConcurrency - Starting concurrency level * @param maxConcurrency - Maximum concurrency allowed * @param adjustmentInterval - How often to adjust concurrency (ms) * @param performanceThreshold - Success rate threshold for increasing concurrency * @returns Promise that resolves to array of results */ export declare function rollingConcurrency(tasks: (() => Promise)[], initialConcurrency?: number, maxConcurrency?: number, adjustmentInterval?: number, performanceThreshold?: number): Promise; /** * Adaptive concurrency with automatic backpressure handling * @param tasks - Array of functions that return promises * @param options - Configuration options * @returns Promise that resolves to array of results */ export declare function adaptiveConcurrency(tasks: (() => Promise)[], options?: { initialConcurrency?: number; maxConcurrency?: number; targetLatency?: number; latencyThreshold?: number; sampleSize?: number; }): Promise; export { PQueue }; declare const _default: { limitedPromiseAll: typeof limitedPromiseAll; limitedPromiseAllSettled: typeof limitedPromiseAllSettled; rateLimitedPromiseAll: typeof rateLimitedPromiseAll; throttle: typeof throttle; debounce: typeof debounce; Semaphore: typeof Semaphore; withSemaphore: typeof withSemaphore; adaptiveConcurrency: typeof adaptiveConcurrency; rollingConcurrency: typeof rollingConcurrency; PQueue: typeof PQueue; }; export default _default; //# sourceMappingURL=concurrencyUtils.d.ts.map