# `ZenWebsocket.Client.Connection`
[🔗](https://github.com/ZenHive/zen_websocket/blob/v0.8.0/lib/zen_websocket/client/connection.ex#L1)

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`.

# `cleanup_failed_connection`

```elixir
@spec cleanup_failed_connection(map()) :: map()
```

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

# `continue_connect`

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

Opens the first Gun connection after `init/1`.

# `continue_reconnect`

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

Opens a Gun connection on a scheduled or immediate reconnect.

# `handle_upgrade`

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

Marks the connection connected after a WebSocket upgrade.

# `initial_state`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
