/** * [WHO]: Provides BatchingDispatcher — generic event-buffering with deferred-flush timer, reentrancy protection, and close-time drain * [FROM]: Depends on ./types for DiagnosticHandler; sink-agnostic — no HTTP, no insforge, no SAL semantics * [TO]: Consumed by extensions/builtin/sal/eval/insforge-sink.ts via composition; future ext-telemetry sink reuses the same machinery * [HERE]: core/platform/telemetry/batching-dispatcher.ts - factored out of SAL's eval sink: SAL's scheduleFlush/doFlush/flush/close logic was inherently generic, now reusable */ import type { DiagnosticHandler } from "./types.js"; export interface BatchingDispatcherOptions { /** Per-event work. Errors are caught and reported via onDiagnostic. */ handler: (event: T) => Promise; /** Flush timer interval in ms. Default 2000ms. */ intervalMs?: number; /** Diagnostic source used in fingerprints. e.g. "sal.eval". */ source: string; onDiagnostic?: DiagnosticHandler; } /** * Generic buffer-then-drain dispatcher. Consumers call enqueue() to add work; * a debounced flush timer drains the queue serially through the handler. * close() drains synchronously (best-effort) before letting the process exit. * * Reentrancy: doFlush() loops over splice()'d batches so events arriving while * a flush is in flight are picked up by the same flush cycle. */ export declare class BatchingDispatcher { private pending; private flushTimer; private flushInFlight; private closed; private handler; private intervalMs; private source; private onDiagnostic?; constructor(options: BatchingDispatcherOptions); enqueue(event: T): void; flush(): Promise; close(): Promise; private scheduleFlush; private doFlush; private reportFlushFailure; }