/** * Tiny single-flight semaphore / concurrency limiter. * * Used by log10x_investigate's correlation engine to fan out lag-analysis * queries in parallel while respecting max_parallel_promql_queries without * adding a p-limit dependency. * * Usage: * const limit = createLimiter(30); * const results = await Promise.all(tasks.map((t) => limit(() => t()))); * * The limiter also supports a soft deadline: tasks enqueued after the * deadline resolve immediately with `undefined` so upstream code can tell * whether a slot was filled or skipped. */ export interface Limiter { (fn: () => Promise): Promise; /** Number of tasks currently running. */ active(): number; /** Number of tasks waiting in the queue. */ pending(): number; /** Mark the limiter as soft-expired — new tasks resolve to undefined. */ softExpire(): void; isSoftExpired(): boolean; } export declare function createLimiter(concurrency: number, softDeadlineMs?: number): Limiter; /** * Race a promise against a deadline. Resolves to `null` if `ms` elapses before * `p` settles. Promoted from the offload-status partial-result pattern so every * interactive caller can bound a slow leg uniformly. Note: a client-side race * does not cancel `p` — pair it with a backend-level timeout (the threaded * `timeoutMs` on queryInstant/queryRange) when you also need the in-flight * request aborted. */ export declare function withTimeout(p: Promise, ms: number): Promise; /** * Fan out `fn` over `items` with bounded concurrency and a per-leg deadline, * degrading any slow / failed / soft-expired leg to `null` instead of sinking * the whole batch. Covers the N+1 / serial-loop query shapes (first-seen, * drift, rank-by-shape, metrics-that-moved, commitment per-week, preview-filter): * a bare `for (const x of xs) await query(x)` over 100 items is a multi-minute * hang even with a per-leg timeout; this caps both the width and each leg. * * Result order matches `items`. `null` means that leg did not produce a value * (timed out, threw, or was skipped after the soft deadline) — callers map it * to their existing unknown/skip handling. */ export declare function boundedFanout(items: I[], fn: (item: I, index: number) => Promise, opts: { concurrency: number; timeoutMs?: number; softDeadlineMs?: number; }): Promise>;