import { InspectorBody } from "./AvoNetworkCallsHandler"; export declare const MAX_TIMER_MS = 2147483647; export declare const MAX_IN_FLIGHT_SENDS = 4; export declare const MAX_WAITING_EVENTS = 10000; export declare const BACKPRESSURE_WAITING_EVENTS = 1000; export declare const BACKPRESSURE_MAX_WAIT_MS = 10000; export interface AvoBatchOptions { batchSize: number; batchFlushSeconds: number; maxQueueSize: number; disableBatchTimer: boolean; } /** * In-memory pending batch buffer. Node runs this on a single thread, so appending and * the swap-and-clear in drain() are atomic without a lock; the send itself happens in * the dispatch callback, after the buffer has been swapped out. At most * MAX_IN_FLIGHT_SENDS dispatches run at once; later batches wait in order. */ export declare class AvoBatchQueue { private options; private dispatch; private dropped; private track; private buffer; private waiting; private waitingEvents; private inFlight; private inFlightEventCount; private capacityWaiters; private capacityTimer; private flushTimer; private bufferOutcome; /** * @param dispatch sends one batch; must not reject. * @param dropped the outcome for a batch discarded before it was sent. * @param track called with each batch's outcome promise as soon as it is swapped out. */ constructor(options: AvoBatchOptions, dispatch: (batch: Array) => Promise, dropped: T, track?: (outcome: Promise) => Promise); /** Events in the unsent buffer (bounded by maxQueueSize). */ get length(): number; /** Events in batches waiting for a send slot (bounded by MAX_WAITING_EVENTS). */ get waitingLength(): number; /** Events in batches being sent. */ get inFlightEvents(): number; /** * Appends an event and evaluates the size trigger. Returns the send promise when * this call dispatched a batch, otherwise null. */ enqueue(event: InspectorBody): Promise | null; /** * The outcome of the batch that will carry the events buffered now, whichever drain (size * trigger, timer, flush) swaps them out. Null when the buffer is empty. */ bufferedBatchOutcome(): Promise | null; /** Swaps out every buffered event and dispatches them as one batch. */ drain(): Promise | null; /** * Resolves once fewer than BACKPRESSURE_WAITING_EVENTS events wait for a send slot (at * once if they already do), when the backlog overflows, and at the latest after * BACKPRESSURE_MAX_WAIT_MS. clear() resolves it too. */ whenBelowBackpressure(): Promise; /** Tracks waiting on backpressure. */ get capacityWaiterCount(): number; private releaseCapacityWaiters; /** Discards every buffered or waiting event unsent and cancels the scheduled flush. */ clear(): void; private startSends; private dropOldestWaiting; private scheduleFlush; private clearTimer; get hasScheduledFlush(): boolean; }