WebsockexNova.Gun.Helpers.BehaviorHelpers (WebsockexNova v0.1.1)
View SourceHelper functions for calling behavior callbacks consistently.
This module provides a standardized way to call behavior callbacks, handle their responses, and update state accordingly. It ensures proper error handling and consistent behavior throughout the application.
Summary
Functions
Calls the connection handler's handle_connect callback.
Calls the connection handler's handle_disconnect callback.
Calls the connection handler's handle_frame callback.
Calls the connection handler's handle_timeout callback.
Functions
@spec call_handle_connect(WebsockexNova.Gun.ConnectionState.t(), map()) :: {:ok, WebsockexNova.Gun.ConnectionState.t()} | {:reply, atom(), binary(), WebsockexNova.Gun.ConnectionState.t()} | {:close, integer(), binary(), WebsockexNova.Gun.ConnectionState.t()} | {:stop, term(), WebsockexNova.Gun.ConnectionState.t()} | {:error, term()}
Calls the connection handler's handle_connect callback.
Assembles a connection info map from the state, calls the handler, and processes the response.
Parameters
state
- The current connection stateextra_info
- Optional extra information to include in the conn_info map
Returns
{:ok, updated_state}
or error tuple
@spec call_handle_disconnect(WebsockexNova.Gun.ConnectionState.t(), term()) :: {:ok, WebsockexNova.Gun.ConnectionState.t()} | {:reconnect, WebsockexNova.Gun.ConnectionState.t()} | {:stop, term(), WebsockexNova.Gun.ConnectionState.t()}
Calls the connection handler's handle_disconnect callback.
Parameters
state
- The current connection statereason
- The disconnect reason
Returns
{:ok, updated_state}
, {:reconnect, updated_state}
, or {:stop, reason, updated_state}
@spec call_handle_frame( WebsockexNova.Gun.ConnectionState.t(), atom(), binary(), reference() ) :: {:ok, WebsockexNova.Gun.ConnectionState.t()} | {:reply, atom(), binary(), WebsockexNova.Gun.ConnectionState.t(), reference()} | {:close, integer(), binary(), WebsockexNova.Gun.ConnectionState.t(), reference()}
Calls the connection handler's handle_frame callback.
Parameters
state
- The current connection stateframe_type
- Type of the frame (:text, :binary, etc.)frame_data
- Data contained in the framestream_ref
- Reference to the stream that received the frame
Returns
{:ok, updated_state}
or other handler return value with updated state
@spec call_handle_timeout(WebsockexNova.Gun.ConnectionState.t()) :: {:ok, WebsockexNova.Gun.ConnectionState.t()} | {:reconnect, WebsockexNova.Gun.ConnectionState.t()} | {:stop, term(), WebsockexNova.Gun.ConnectionState.t()}
Calls the connection handler's handle_timeout callback.
Parameters
state
- The current connection state
Returns
{:ok, updated_state}
, {:reconnect, updated_state}
, or {:stop, reason, updated_state}