/** * Concurrency utilities for parallel execution with limits. */ /** * Options for parallel execution. */ export interface ParallelOptions { /** Maximum concurrent tasks (default: 3) */ concurrency?: number; /** Timeout per task in milliseconds (default: no timeout) */ taskTimeoutMs?: number; /** Callback when a task completes */ onTaskComplete?: (result: T, index: number) => void; /** Callback when a task fails */ onTaskError?: (error: Error, index: number) => void; } /** * Result of a parallel execution. */ export interface ParallelResult { /** Successful results */ results: T[]; /** Errors by index */ errors: Map; /** Whether all tasks succeeded */ allSucceeded: boolean; } /** * Execute tasks in parallel with a concurrency limit. * Uses a semaphore pattern to limit concurrent execution. * * @param tasks - Array of async task functions to execute * @param options - Parallel execution options * @returns Results of all tasks */ export declare function parallelLimit(tasks: Array<() => Promise>, options?: ParallelOptions): Promise>; /** * Execute tasks in parallel with a concurrency limit, collecting all results. * Unlike parallelLimit, this version preserves order and includes errors inline. * * @param items - Array of items to process * @param fn - Async function to process each item * @param options - Parallel execution options * @returns Array of results (or errors) in original order */ export declare function mapLimit(items: T[], fn: (item: T, index: number) => Promise, options?: ParallelOptions): Promise>; /** * Create a semaphore for limiting concurrent access to a resource. */ export declare function createSemaphore(limit: number): { acquire(): Promise; release(): void; readonly available: number; readonly waiting: number; }; /** * Mutex for ensuring exclusive access to a resource. */ export declare function createMutex(): { acquire(): Promise; release(): void; readonly available: number; readonly waiting: number; }; /** * Thread-safe accumulator for collecting results from parallel tasks. */ export declare class SafeAccumulator { private items; private mutex; /** * Add an item to the accumulator. */ add(item: T): Promise; /** * Add multiple items to the accumulator. */ addAll(items: T[]): Promise; /** * Get all accumulated items. */ getAll(): T[]; /** * Get the current count. */ get count(): number; } /** * Thread-safe map for collecting keyed results. */ export declare class SafeMap { private map; private mutex; /** * Set a value in the map. */ set(key: K, value: V): Promise; /** * Get a value from the map. */ get(key: K): V | undefined; /** * Check if a key exists. */ has(key: K): boolean; /** * Get all entries. */ entries(): IterableIterator<[K, V]>; /** * Get all values. */ values(): IterableIterator; /** * Get the current size. */ get size(): number; } //# sourceMappingURL=concurrency.d.ts.map