kalevala v0.1.0 Kalevala.Communication.Channel behaviour View Source

A GenServer to handle channel communication

Link to this section Summary

Types

The "topic" in the channel pub/sub

Config is saved and stored in the GenServer, passed in for each callback

Options are for each subscribe/publish request

Functions

Returns a specification to start this module under a supervisor.

Publish a new message

Callbacks

Called during initialization

Called before a message is allowed to publish on the channel

Called before a pid is allowed to subscribe to a channel

Called before a pid is allowed to unsubscribe to a channel

Link to this section Types

Link to this type

channel_name()

View Source
channel_name() :: String.t()

The "topic" in the channel pub/sub

This might be a simple global channel name or something specific to rooms, maybe rooms:id.

Config is saved and stored in the GenServer, passed in for each callback

Link to this type

options()

View Source
options() :: map()

Options are for each subscribe/publish request

This may contain information like charcater data

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

publish(pid, message, options)

View Source

Publish a new message

Link to this function

subscribe(pid, channel_name, subscriber_pid, options)

View Source

Subscribe to a new channel

Allows for the callback_module to reject subscription

Link to this function

unsubscribe(pid, channel_name, subscriber_pid, options)

View Source

Unsubscribe to a new channel

Allows for the callback_module to reject unsubscription

Link to this section Callbacks

Called during initialization

You can change any of the config you wish on start of the gen server

Link to this callback

publish_request(channel_name, arg2, options, config)

View Source
publish_request(channel_name(), Kalevala.Event.message(), options(), config()) ::
  :ok

Called before a message is allowed to publish on the channel

Link to this callback

subscribe_request(channel_name, options, config)

View Source
subscribe_request(channel_name(), options(), config()) :: :ok

Called before a pid is allowed to subscribe to a channel

Link to this callback

unsubscribe_request(channel_name, options, config)

View Source
unsubscribe_request(channel_name(), options(), config()) :: :ok

Called before a pid is allowed to unsubscribe to a channel