Skip to main content
Version: v10.0.0

createReconnectingConnection

The connection lifecycle shared by the socket adapters. The adapter opens transports, the engine owns everything around them: one attempt at a time, the connection timeout, reconnecting with backoff and jitter, the attempt counter, the network and focus signals of the app manager, and closing on purpose.

  • An attempt succeeds when the adapter calls ready() . The connection timeout covers the whole way there.
  • A lost connection is retried after reconnectDelay (full jitter between reconnectTime and maxReconnectTime

by default), unless shouldReconnect says otherwise - by default a normal closure (1000) of the server stays closed. The client's own closes are never retried.

  • The attempt counter resets only after the connection stayed ready for minUptime , so reconnect also bounds connections that drop right after opening.
  • Offline drops the transport and pauses, without counting attempts. Online connects at once.
  • Focus skips a pending reconnection delay.
  • The socket should be connected from the first connect() until disconnect()

autoConnect only decides the first connection, recovery never depends on it.

Events of a replaced, timed out or closed transport are ignored, so they never change the socket.


Import
import { createReconnectingConnection } from "@hyper-fetch/sockets"

Parameters​

createReconnectingConnection<Adapter>(__namedParameters: ReconnectingConnectionOptionsType<Adapter>)
Parameters
NameTypeDescription
__namedParameters
ReconnectingConnectionOptionsType<Adapter>

Returns​

type ReconnectingConnectionType = {
connect: () => Promise<boolean>;
disconnect: () => Promise<boolean>;
dispose: () => void;
reconnect: () => Promise<void>;
}
createReconnectingConnection
NameTypeDescription
connect
() => Promise<boolean>

Connects now - skipping a pending reconnection delay. Resolves with true once the connection is ready.

disconnect
() => Promise<boolean>

Closes the connection on purpose. It stays closed until connect() or reconnect() is called.

dispose
() => void

Removes the app manager listeners and the timers. The connection itself is closed with disconnect() .

reconnect
() => Promise<void>

Replaces the connection with a new one, also after disconnect() . Counts as a reconnection attempt.