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 disconnect_reason() :: {:close, code :: non_neg_integer() | nil, reason :: binary() | nil}
@type frame() :: Mint.WebSocket.shorthand_frame() | Mint.WebSocket.frame()
@type state() :: term()
Callbacks
@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.
@callback handle_connect(Mint.Types.headers(), state()) :: call_result()
Invoked after connecting or reconnecting.
@callback handle_disconnect(disconnect_reason(), state()) :: {:ok, state()}
Invoked after disconnecting.
@callback handle_in(frame(), state()) :: call_result()
Invoked when the server receives a WebSocket frame.
@callback handle_info(any(), state()) :: call_result()
Invoked when the server receives any message that is not a call or WebSocket frame.
Functions
Calls the given server.
Wrapper for :gen_statem.call/3
.
Replies to the given Late.call/3
caller.
Wrapper for :gen_statem.reply/2
.