PubSub v1.1.1 PubSub View Source
Publish-Subscribe utility process. Use start_link/0
to start it:
PubSub.start_link()
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Callback implementation for GenServer.init/1
.
Delivers a message to the given topic.
Starts the server.
Subscribes a process to the given topic.
Returns a list of pids representing the processes that are currently subscribed to the given topic.
Returns a list of the current topics.
Unsubscribes a process from a given topic.
Link to this section Types
Link to this section Functions
Specs
Returns a specification to start this module under a supervisor.
See Supervisor
.
Callback implementation for GenServer.init/1
.
Specs
Delivers a message to the given topic.
Example
iex> PubSub.publish(:my_topic, "Hi there!")
:ok
Specs
start_link(list()) :: GenServer.on_start()
Starts the server.
Specs
Subscribes a process to the given topic.
Example
iex> pid = self()
iex> PubSub.subscribe(pid, :my_topic)
:ok
Specs
Returns a list of pids representing the processes that are currently subscribed to the given topic.
Example
iex> pid = self()
iex> PubSub.subscribe(pid, :my_topic)
iex> [subscriber] = PubSub.subscribers(:my_topic)
iex> subscriber == pid
true
Specs
topics() :: [topic()]
Returns a list of the current topics.
Example
iex> pid = self()
iex> PubSub.subscribe(pid, :my_topic)
iex> PubSub.subscribe(pid, :your_topic)
iex> PubSub.topics
[:my_topic, :your_topic]
Specs
Unsubscribes a process from a given topic.
Example
iex> pid = self()
iex> PubSub.unsubscribe(pid, :my_topic)
:ok