OffBroadwayWebSocket.State (off_broadway_websocket v0.0.1)

Manages the state for WebSocket producer in an Off-Broadway setup. This includes demand tracking, reconnection parameters, and message queuing.

Summary

Functions

Creates a new %State{} struct with specified options.

Resets the reconnect state within a %State{} struct.

Types

@type t() :: %OffBroadwayWebSocket.State{
  await_timeout: non_neg_integer(),
  conn_pid: pid() | nil,
  connect_timeout: non_neg_integer(),
  http_opts: map(),
  last_pong: DateTime.t() | nil,
  max_demand: non_neg_integer(),
  message_queue: OffBroadwayWebSocket.Types.queue(),
  min_demand: non_neg_integer(),
  path: String.t(),
  queue_size: non_neg_integer(),
  reconnect_attempts: non_neg_integer(),
  reconnect_delay: non_neg_integer(),
  reconnect_initial_delay: non_neg_integer(),
  reconnect_max_delay: non_neg_integer(),
  stream_ref: reference() | nil,
  total_demand: non_neg_integer(),
  url: String.t(),
  ws_opts: map(),
  ws_timeout: non_neg_integer()
}

Functions

@spec new(keyword()) :: t()

Creates a new %State{} struct with specified options.

Parameters

  • opts: A keyword list of options, including:
    • :broadway - Broadway-related options, specifically demand settings.
    • :url - The WebSocket URL.
    • :path - The WebSocket path.
    • :reconnect_delay - Optional delay in milliseconds for reconnection.
    • :ws_opts - WebSocket options for gun.
    • :http_opts - HTTP options for gun.
    • :ws_timeout - Optional timeout for WebSocket operations.

Returns

  • A %State{} struct initialized with the provided options and default values.
Link to this function

reset_reconnect_state(state)

@spec reset_reconnect_state(t()) :: t()

Resets the reconnect state within a %State{} struct.

Sets reconnect_attempts to 0 and resets reconnect_delay to the initial delay specified by @default_reconnect_initial_delay.

Parameters

  • state: The %State{} struct whose reconnect state is being reset.

Returns

  • An updated %State{} struct with reconnect_attempts set to 0 and reconnect_delay set to @default_reconnect_initial_delay.