Hub.Channel (hub v1.0.1)

GenServer that handles a single channel. This serializes publishes, subscribes and unsubscribes on that channel, and makes sure no race condition can occur.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Callback implementation for GenServer.init/1.

Publishes the message to all matching subscribers of this channel. Returns number of subscribers that the message was sent to.

Starts the Channel

Get all subscribers from channel

Unsubscribes using the reference returned on subscribe

Unsubscribes and flushes any messages in the mailbox that matches the subscribed pattern

Link to this section Types

Specs

count() :: pos_integer() | :infinity

Specs

pattern() :: any()
Link to this type

subscribe_option()

Specs

subscribe_option() :: {:pid, pid()} | {:count, count()} | {:multi, boolean()}
Link to this type

subscribe_options()

Specs

subscribe_options() :: [subscribe_option()]
Link to this type

subscription_ref()

Specs

subscription_ref() :: {pid(), reference()}

Link to this section Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

init(channel_name)

Callback implementation for GenServer.init/1.

Link to this function

publish(channel, message)

Specs

publish(pid(), any()) :: non_neg_integer()

Publishes the message to all matching subscribers of this channel. Returns number of subscribers that the message was sent to.

Link to this function

start_link(channel_name)

Specs

start_link(String.t()) :: GenServer.on_start()

Starts the Channel

Link to this function

subscribe_quoted(channel, quoted_pattern, options \\ [])

Specs

subscribe_quoted(pid(), any(), subscribe_options()) ::
  {:ok, subscription_ref()} | {:error, reason :: String}

Subscribes with the quoted pattern

Link to this function

subscribers(channel)

Specs

subscribers(pid()) :: [Hub.Subscriber.t()]

Get all subscribers from channel

Link to this function

unsubscribe(arg)

Specs

unsubscribe(subscription_ref()) :: :ok

Unsubscribes using the reference returned on subscribe

Link to this function

unsubscribe_and_flush(subscription_ref)

Specs

unsubscribe_and_flush(subscription_ref()) :: :ok

Unsubscribes and flushes any messages in the mailbox that matches the subscribed pattern