Skip to main content
Version: v10.0.0

ConnectionAttemptType

Handle of one connection attempt, given to the adapter's open


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

Preview​

type ConnectionAttemptType<Adapter> = {
connection: SocketConnectionType<Adapter>;
interrupted: () => void;
isCurrent: () => boolean;
lost: (loss?: ConnectionLossType) => void;
ready: () => void;
}

Structure​

ConnectionAttemptType
NameTypeDescription
connection
SocketConnectionType<Adapter>

Connection details after the onConnect interceptors

interrupted
() => void

The connection dropped and the transport reconnects by itself (e.g. EventSource ). The socket is reported as disconnected and connecting - ready() brings it back, otherwise the connection timeout ends the attempt.

isCurrent
() => boolean

false once the attempt was replaced, timed out or closed - its transport must not change the socket anymore

lost
(loss?: ConnectionLossType) => void

The transport is gone. The engine closes it and decides about the next attempt.

ready
() => void

The connection can carry messages - call it on open, or after the handshake of protocols that have one. Calling it again after interrupted() reports that the transport recovered on its own.