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
Subscribes with the quoted pattern
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
count()
Specs
count() :: pos_integer() | :infinity
pattern()
Specs
pattern() :: any()
subscribe_option()
Specs
subscribe_options()
Specs
subscribe_options() :: [subscribe_option()]
subscription_ref()
Specs
Link to this section Functions
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
init(channel_name)
Callback implementation for GenServer.init/1
.
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.
start_link(channel_name)
Specs
start_link(String.t()) :: GenServer.on_start()
Starts the Channel
subscribe_quoted(channel, quoted_pattern, options \\ [])
Specs
subscribe_quoted(pid(), any(), subscribe_options()) :: {:ok, subscription_ref()} | {:error, reason :: String}
Subscribes with the quoted pattern
subscribers(channel)
Specs
subscribers(pid()) :: [Hub.Subscriber.t()]
Get all subscribers from channel
unsubscribe(arg)
Specs
unsubscribe(subscription_ref()) :: :ok
Unsubscribes using the reference returned on subscribe
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