import type { JsonRpcId, JsonRpcSuccessResponse } from '@enbox/dwn-clients'; import type { ProgressToken, SubscriptionMessage } from '@enbox/dwn-sdk-js'; /** Default maximum number of unacknowledged events before pausing delivery. */ export declare const DEFAULT_MAX_IN_FLIGHT = 32; /** Maximum buffer size; awaited producers pause here to prevent unbounded memory growth. */ export declare const MAX_BUFFER_SIZE = 1000; /** Maximum time a full buffer may wait for ACKs before its subscription closes. */ export declare const MAX_BUFFER_WAIT_MS = 30000; /** * Per-subscription flow controller that enforces a sliding window of * unacknowledged events. When the window is full, incoming events are * buffered. When the client sends `rpc.ack` with a cursor, events up * to that cursor are acknowledged and buffered events are flushed. * * Producers pause at {@link MAX_BUFFER_SIZE} until ACKs free capacity. A * {@link MAX_BUFFER_WAIT_MS} deadline closes stalled subscriptions. Producers * that push past capacity without awaiting are closed immediately. */ export declare class FlowController { private readonly subscriptionId; private readonly maxInFlight; private readonly send; private readonly onOverflow; /** Ordered list of progress tokens for events that have been sent but not yet acknowledged. */ private unacked; /** Buffer of events waiting to be sent once the window opens. */ private buffer; /** Whether the controller has been closed. */ private closed; private capacityWait?; constructor(subscriptionId: JsonRpcId, maxInFlight: number, send: (response: JsonRpcSuccessResponse) => void, onOverflow: () => void); /** * Accept an incoming {@link SubscriptionMessage} from the EventLog listener. * If the window has room, send immediately. Otherwise buffer. At buffer * capacity, the producer must await the returned promise before pushing again. */ push(message: SubscriptionMessage): void | Promise; /** Stops delivery and releases frames on unsubscribe, disconnect, or overflow. */ close(): void; private waitForCapacity; /** Ends stalled delivery and reports its terminal error outside the full ACK window. */ private fail; private resumeCapacity; /** * Process an `rpc.ack` for this subscription. Acknowledges all events up * to and including the given cursor, then flushes buffered events into the * newly opened window slots. */ ack(cursor: ProgressToken): void; /** * Returns the number of events currently in flight (sent but unacknowledged). */ get inFlightCount(): number; /** * Returns the number of events currently buffered (waiting to be sent). */ get bufferCount(): number; /** * Sends a single message over the wire and tracks its cursor. */ private sendMessage; } //# sourceMappingURL=flow-controller.d.ts.map