Bourse.WS.ConnectionOwner (bourse v0.7.0)

Copy Markdown View Source

Holds the routed-host WebSocket clients for one Bourse.WS connection.

Owners start under Bourse.WS.ConnectionOwner.Supervisor (:temporary) and are linked to the process that opened the Bourse.WS connection. Stopping or crashing an owner closes every socket it still holds, so a dead owner cannot leave an unreachable routed host, and an owner whose process dies is visible to its dependents.

Summary

Functions

Returns the client for url, connecting through connect_fun when it is new.

Returns a specification to start this module under a supervisor.

Starts a supervised owner holding zen_client at url.

Stops the owner. Remaining clients are closed from terminate/2.

Removes and returns every held client so the caller can close them.

Functions

checkout(owner, connect_fun, url, opts, timeout)

@spec checkout(
  pid(),
  (String.t(), keyword() -> {:ok, ZenWebsocket.Client.t()} | {:error, term()}),
  String.t(),
  keyword(),
  timeout()
) :: {:ok, ZenWebsocket.Client.t()} | {:error, term()}

Returns the client for url, connecting through connect_fun when it is new.

child_spec(init_arg)

@spec child_spec({String.t(), ZenWebsocket.Client.t()}) :: Supervisor.child_spec()

Returns a specification to start this module under a supervisor.

See Supervisor.

start(url, zen_client)

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

Starts a supervised owner holding zen_client at url.

stop(owner, timeout)

@spec stop(pid(), timeout()) :: :ok

Stops the owner. Remaining clients are closed from terminate/2.

take(owner, timeout)

@spec take(pid(), timeout()) :: {:ok, [ZenWebsocket.Client.t()]} | {:error, term()}

Removes and returns every held client so the caller can close them.