View Source Late behaviour (late v0.3.0)

Example

defmodule MyConnection do
  @behaviour Late

  @impl true
  def init(_args) do
    {:ok, %{from: nil}}
  end

  @impl true
  def handle_call({:something, query}, from, state) do
    {:noreply, stuff}
  end

  @impl true
  def handle_in({:text, text}, state) do
    {:reply, [frame], new_state}
  end
end

Summary

Callbacks

Invoked when the server receives a call message sent by Late.call/3.

Invoked after connecting or reconnecting.

Invoked after disconnecting.

Invoked when the server receives a WebSocket frame.

Invoked when the server receives any message that is not a call or WebSocket frame.

Types

@type call_result() ::
  {:ok, state()} | {:reply, [frame()], state()} | {:stop, any(), state()}
@type disconnect_reason() ::
  {:close, code :: non_neg_integer() | nil, reason :: binary() | nil}
@type state() :: term()

Callbacks

Link to this callback

handle_call(term, {}, state)

View Source (optional)
@callback handle_call(term(), {pid(), term()}, state()) :: call_result()

Invoked when the server receives a call message sent by Late.call/3.

You must reply to the calling process using Late.reply/2. Returning a {:reply, [frame], state} tuple will send the frames to the WebSocket server, not the calling process.

Link to this callback

handle_connect(headers, state)

View Source (optional)
@callback handle_connect(Mint.Types.headers(), state()) :: call_result()

Invoked after connecting or reconnecting.

Link to this callback

handle_disconnect(disconnect_reason, state)

View Source (optional)
@callback handle_disconnect(disconnect_reason(), state()) :: {:ok, state()}

Invoked after disconnecting.

Link to this callback

handle_in(frame, state)

View Source (optional)
@callback handle_in(frame(), state()) :: call_result()

Invoked when the server receives a WebSocket frame.

Link to this callback

handle_info(any, state)

View Source (optional)
@callback handle_info(any(), state()) :: call_result()

Invoked when the server receives any message that is not a call or WebSocket frame.

@callback init(term()) :: {:ok, state()}

Functions

Link to this function

call(server, message, timeout \\ 5000)

View Source

Calls the given server.

Wrapper for :gen_statem.call/3.

Replies to the given Late.call/3 caller.

Wrapper for :gen_statem.reply/2.

Link to this function

start_link(module, args, opts)

View Source