/** * Generic in-flight-capped worker pool. * * Used by: * - runBatchCommands (ctx_batch_execute parallel branch) * - runBatchFetch (ctx_fetch_and_index batch path) * * Returns Promise.allSettled-style results so one job's throw cannot * strand siblings. Caller maps fulfilled/rejected per index. Output * order is preserved by input index (not completion order). * * Designed to be the SINGLE concurrency primitive for the project — * all "run N independent operations with at most M in flight" needs * route here. Avoids the worker-pool copy-paste flagged in the * concurrency PRD architectural review (finding G). */ export interface PoolJob { run(): Promise; } export interface RunPoolOptions { /** Hard concurrency cap (1-N). Auto-clamped to job count. */ concurrency: number; /** Optional: also clamp by `os.cpus().length` (memory-pressure safety). Default false. */ capByCpuCount?: boolean; /** Optional: per-settled callback (e.g. for progress reporting / metrics). */ onSettled?: (idx: number, result: PromiseSettledResult) => void; } export interface RunPoolResult { /** Per-index settled result, ordered by input index. */ settled: PromiseSettledResult[]; /** Concurrency actually used after all caps applied. */ effectiveConcurrency: number; /** True when effectiveConcurrency < requested concurrency. */ capped: boolean; } export declare function runPool(jobs: PoolJob[], opts: RunPoolOptions): Promise>;