export type ConnectedHandler = () => Promise; export type DisconnectedHandler = () => Promise; export type ReconnectRequestedHandler = (reason: string, error: unknown) => void; /** * Represents the lifecycle state for a Chronicle connection. */ export declare class ConnectionLifecycle { private readonly _onConnected; private readonly _onDisconnected; private readonly _onFailed; private readonly _onReconnectRequested; private _failure?; private _isConnected; private _connectionId; /** * Gets whether the connection is currently connected. */ get isConnected(): boolean; /** Gets the terminal connection failure, if recovery has stopped. */ get failure(): Error | undefined; /** * Gets the current connection identifier. */ get connectionId(): string; /** * Registers a callback for when the connection is connected. * @param handler - Callback to invoke on connect. * @returns A function that unsubscribes the callback. */ onConnected(handler: ConnectedHandler): () => void; /** * Registers a callback for when the connection is disconnected. * @param handler - Callback to invoke on disconnect. * @returns A function that unsubscribes the callback. */ onDisconnected(handler: DisconnectedHandler): () => void; /** * Registers a callback for when something asks the whole client to reconnect. * @param handler - Callback to invoke with the reason and the error behind the request. * @returns A function that unsubscribes the callback. */ onReconnectRequested(handler: ReconnectRequestedHandler): () => void; /** * Asks the whole client to drop its session and reconnect with a new connection id, for instance because * the kernel no longer knows the current one. * * A request about a connection id that has already been replaced is ignored: the session it reports on is * gone, and the observer that reported it is opened again by the reconnect that replaced it. * @param connectionId - The connection id of the session the request is about. * @param reason - Why the reconnect is requested. * @param error - The error behind the request. * @param onError - Called with the error when a handler throws. */ requestReconnect(connectionId: string, reason: string, error: unknown, onError: (error: unknown) => void): void; /** * Replaces the connection id, so the next session is registered with one the kernel has not seen. */ renewConnectionId(): void; /** Registers a callback for a terminal connection failure. */ onFailed(handler: (error: Error) => Promise): () => void; /** Stops recovery and notifies observers of the terminal connection failure. */ failed(error: Error, onError: (error: unknown) => void): Promise; /** * Marks lifecycle as connected and invokes connected handlers. */ connected(onError: (error: unknown) => void): Promise; /** * Marks lifecycle as disconnected and invokes disconnected handlers. */ disconnected(onError: (error: unknown) => void): Promise; private invokeHandler; } //# sourceMappingURL=ConnectionLifecycle.d.ts.map