Class PersistentConnection<ConnectAddress, Connection>

Type Parameters

Constructors

Properties

params: {
    connect: (address: ConnectAddress) => Promise<Connection>;
    onClose?: () => MaybePromise<void>;
    onError?: (
        error: Error,
        connection: null | Connection,
        state: ReconnectionState,
    ) => MaybePromise<OnErrorAction>;
    onOpen: (connection: Connection) => Promise<void>;
    onWait?: (wait: number) => void;
    strategy?: ReconnectionStrategy;
}

Type declaration

  • connect: (address: ConnectAddress) => Promise<Connection>
  • OptionalonClose?: () => MaybePromise<void>
  • OptionalonError?: (
        error: Error,
        connection: null | Connection,
        state: ReconnectionState,
    ) => MaybePromise<OnErrorAction>

    Function that will be called whenever an error happens while connecting (in which case connection will be null) or inside onOpen.

    (err) => err instanceof ConnectionClosedError ? 'reconnect' : 'close'

  • onOpen: (connection: Connection) => Promise<void>

    Function to call once the connection is open

    As soon as the promise is resolved the connection will be closed (and will not be re-opened automatically), so this is the best place to put your recv loop

  • OptionalonWait?: (wait: number) => void
  • Optionalstrategy?: ReconnectionStrategy

Accessors

Methods