import type { IChronicleLogger } from '../logging/IChronicleLogger.js'; import type { ConnectRequest } from '@cratis/chronicle.contracts'; /** * Overrides for how long {@link KernelKeepAlive} waits before giving up on the kernel. */ export interface KeepAliveTimeouts { /** How long to wait for a keep-alive before treating the connection as dead. */ idleTimeoutMs?: number; /** How long a single answer may take before the connection is considered dead. */ answerTimeoutMs?: number; } /** * The subset of the connection service {@link KernelKeepAlive} needs, so it can be * exercised without a live kernel. */ export interface IKeepAliveConnections { connect(request: ConnectRequest, options?: { signal?: AbortSignal; }): AsyncIterable; connectionKeepAlive(request: object, options?: { signal?: AbortSignal; }): Promise; } /** * Drives the client half of Chronicle's keep-alive ping-pong. * * The kernel pushes a `ConnectionKeepAlive` down the `Connect` server stream once * per second, and for each one the client must call the separate unary * `ConnectionKeepAlive` RPC back — that is what bumps `LastSeen` on the kernel and * keeps the client registered. A client that stops answering is evicted, its * observers are unsubscribed, and reactors and reducers go silent while appends * keep working. * * Eviction does not close the `Connect` stream, so a dead session usually presents * as a stream that simply goes quiet rather than one that errors. Both a gap * between keep-alives and an ended stream therefore mean the same thing: the * connection is gone and the client must reconnect. */ export declare class KernelKeepAlive { private readonly connections; private readonly onConnectionLost; /** * How long to wait for a keep-alive before treating the connection as dead. * The kernel emits one per second and evicts clients whose `LastSeen` falls * more than five seconds behind, which is the threshold the C# client uses too. */ static readonly defaultIdleTimeoutMs = 5000; /** How long a single answer may take before the connection is considered dead. */ static readonly defaultAnswerTimeoutMs = 5000; private readonly _logger; private readonly _idleTimeoutMs; private readonly _answerTimeoutMs; /** * Creates a new {@link KernelKeepAlive}. * @param connections - The connection service to ping-pong with. * @param onConnectionLost - Called once when the connection is found to be dead. * @param timeouts - Overrides for the default timeouts. */ constructor(connections: IKeepAliveConnections, onConnectionLost: (reason: string, error: unknown) => void, timeouts?: KeepAliveTimeouts, logger?: IChronicleLogger); /** * Opens the `Connect` stream and answers the first keep-alive, establishing the * client's registration with the kernel. Resolves once the kernel has been heard * from; the ongoing ping-pong then continues in the background until the * connection is lost or `signal` is aborted. * @param request - The connect request identifying this client. * @param signal - Aborted to stop the keep-alive entirely. */ start(request: ConnectRequest, signal: AbortSignal): Promise; private openStream; private run; private answer; private connectionLost; private withTimeout; } //# sourceMappingURL=KernelKeepAlive.d.ts.map