ZenWebsocket.ConnectionRegistry (ZenWebsocket v0.8.0)

Copy Markdown View Source

Opt-in ETS connection tracking, without a GenServer.

Maps a caller-chosen connection id to a Gun pid in a public named ETS table (:zen_websocket_connections), monitoring each pid so dead connections can be swept. The table is created lazily by init/0 and every other function assumes it exists — call init/0 once (typically from your application start) before registering.

ZenWebsocket.Client does not use this registry; it is a utility for consumers that want to look connections up by a stable id.

API Functions

FunctionArityDescriptionParam Kinds
shutdown0Drop all monitors and delete the registry ETS table.-
cleanup_dead1Remove every registration pointing at a dead Gun pid.gun_pid: value
get1Look up the Gun pid registered for a connection id.connection_id: value
deregister1Remove a connection by id and drop its monitor.connection_id: value
register2Register a connection id against a Gun pid and monitor the pid.connection_id: value, gun_pid: value
init0Create the connection registry ETS table if it does not exist.-

Summary

Functions

Cleanup dead connection by PID.

Deregister a connection by ID.

Get connection info by ID.

Initialize the connection registry ETS table.

Register a connection with monitoring.

Cleanup all connections and destroy table.

Functions

cleanup_dead(gun_pid)

@spec cleanup_dead(pid()) :: :ok

Cleanup dead connection by PID.

deregister(connection_id)

@spec deregister(String.t()) :: :ok

Deregister a connection by ID.

get(connection_id)

@spec get(String.t()) :: {:ok, pid()} | {:error, :not_found}

Get connection info by ID.

init()

@spec init() :: :ok

Initialize the connection registry ETS table.

register(connection_id, gun_pid)

@spec register(String.t(), pid()) :: :ok

Register a connection with monitoring.

shutdown()

@spec shutdown() :: :ok

Cleanup all connections and destroy table.