ZenWebsocket.Examples.SupervisedClient (ZenWebsocket v0.4.2)

Copy Markdown View Source

Basic WebSocket client supervision example.

Shows minimal setup for supervised connections. For advanced patterns, see the supervision documentation.

Summary

Functions

Lists all supervised connections.

Starts a supervised WebSocket connection.

Starts multiple supervised connections.

Stops a supervised connection.

Functions

list_connections()

@spec list_connections() :: [pid()]

Lists all supervised connections.

start_connection(url, opts \\ [])

@spec start_connection(
  String.t(),
  keyword()
) :: {:ok, ZenWebsocket.Client.t()} | {:error, term()}

Starts a supervised WebSocket connection.

Example

{:ok, client} = SupervisedClient.start_connection("wss://echo.websocket.org")

start_multiple(configs)

@spec start_multiple([{String.t(), keyword()}]) :: [
  {String.t(), {:ok, ZenWebsocket.Client.t()} | {:error, term()}}
]

Starts multiple supervised connections.

Example

clients = SupervisedClient.start_multiple([
  {"wss://api1.example.com", retry_count: 5},
  {"wss://api2.example.com", heartbeat_interval: 20_000}
])

stop_connection(client_pid)

@spec stop_connection(pid()) :: :ok | {:error, :not_found}

Stops a supervised connection.