Spell.Role.Session
The Spell.Role.Session
module implements the behaviour for a session
role.
Sessions are pseudo-roles; each peer started with Spell.Connect
has Spell.Role.Session
added as the first role in roles
.
Summary↑
await_welcome(peer) | Await the welcome message. Useful for blocking until the session is established |
call_goodbye(peer, options \\ []) | Send a GOODBYE message to the remote peer and wait for the GOODBYE reply |
cast_goodbye(peer, options \\ []) | Send a GOODBYE message to the remote peer. The remote peer should reply with a GOODBYE |
get_features(options) | Callback implementation for |
handle_cast(, , state) | Callback implementation for |
handle_message(welcome, peer, state) | Handle WELCOME, GOODBYE, and ABORT messages |
init(peer_options, options) | Returns the state with the specified realm and role |
on_close(peer, state) | Callback implementation for |
on_open(peer, state) | Send a HELLO message when the connection is opened |
Functions
Specs:
- await_welcome(pid) :: {:ok, Spell.Message.t} | {:error, :timeout}
Await the welcome message. Useful for blocking until the session is established.
Specs:
- call_goodbye(pid, Keyword.t) :: {:ok, Spell.Message.t} | {:error, :timeout}
Send a GOODBYE message to the remote peer and wait for the GOODBYE reply.
This must be called from the peer’s owner, otherwise the listening process won’t receive the GOODBYE message.
Specs:
- cast_goodbye(pid, Keyword.t) :: :ok
Send a GOODBYE message to the remote peer. The remote peer should reply with a GOODBYE.
Callback implementation for Spell.Role.get_features/1
.
Callback implementation for Spell.Role.handle_cast/3
.
Handle WELCOME, GOODBYE, and ABORT messages.
Behaviour
- WELCOME: set the peer session
- GOODBYE: close the connection normally
- ABORT: close the connection with an error. With the default supervision settings, the peer will be restarted.
Returns the state with the specified realm and role.
peer_options :: Map.t
Callback implementation for Spell.Role.on_close/2
.
Send a HELLO message when the connection is opened.