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 betweenreconnectTimeandmaxReconnectTime
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, soreconnectalso 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()untildisconnect()
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 { createReconnectingConnection } from "@hyper-fetch/sockets"
Parameters
createReconnectingConnection<Adapter>(__namedParameters: ReconnectingConnectionOptionsType<Adapter>)
| Name | Type | Description |
|---|---|---|
| __namedParameters | |
Returns
type ReconnectingConnectionType = {
connect: () => Promise<boolean>;
disconnect: () => Promise<boolean>;
dispose: () => void;
reconnect: () => Promise<void>;
}
| Name | Type | Description |
|---|---|---|
| connect | | Connects now - skipping a pending reconnection delay. Resolves with
|
| disconnect | | Closes the connection on purpose. It stays closed until
|
| dispose | | Removes the app manager listeners and the timers. The connection itself is closed with
|
| reconnect | | Replaces the connection with a new one, also after
|

