ZenWebsocket.Client.Connection (ZenWebsocket v0.8.0)

Copy Markdown View Source

Gun connection open, upgrade, and cleanup for ZenWebsocket.Client.

Runs inside the Client GenServer process so Gun messages keep the same owner. Attempt-identity timers are preserved from the Task 2 rewrite. Retry decisions live in ZenWebsocket.Client.Retry.

Summary

Functions

Fails pending requests, cancels timers, and closes the Gun connection.

Opens the first Gun connection after init/1.

Opens a Gun connection on a scheduled or immediate reconnect.

Marks the connection connected after a WebSocket upgrade.

Builds the GenServer state used by Client.init/1.

Functions

cleanup_failed_connection(state)

@spec cleanup_failed_connection(map()) :: map()

Fails pending requests, cancels timers, and closes the Gun connection.

continue_connect(state)

@spec continue_connect(map()) ::
  {:noreply, map()}
  | {:noreply, map(), {:continue, {:connection_failed, term()}}}

Opens the first Gun connection after init/1.

continue_reconnect(state)

@spec continue_reconnect(map()) ::
  {:noreply, map()}
  | {:noreply, map(), {:continue, {:connection_failed, term()}}}

Opens a Gun connection on a scheduled or immediate reconnect.

handle_upgrade(state, headers)

@spec handle_upgrade(map(), term()) :: {:noreply, map()}

Marks the connection connected after a WebSocket upgrade.

initial_state(config, opts)

@spec initial_state(
  ZenWebsocket.Config.t(),
  keyword()
) :: map()

Builds the GenServer state used by Client.init/1.