PubSub
Publish-Subscribe utility process. Use start_link/0 to start it:
PubSub.start_link()
Summary↑
publish(topic, message) | Delivers a message to the given topic |
start_link() | Starts the server |
subscribe(pid, topic) | Subscribes a process to the given topic |
subscribers(topic) | Returns a list of pids representing the processes that are currently subscribed to the given topic |
topics() | Returns a list of the current topics |
unsubscribe(pid, topic) | Unsubscribes a process from a given topic |
Types ↑
topic :: binary
message :: binary
Functions
Specs:
- publish(binary, message) :: :ok
Delivers a message to the given topic.
Example
iex> PubSub.publish(:my_topic, "Hi there!")
:ok
Starts the server.
Specs:
- subscribe(pid, topic) :: :ok
Subscribes a process to the given topic.
Example
iex> PubSub.subscribe(pid, :my_topic)
:ok
Specs:
- subscribers(topic) :: [pid]
Returns a list of pids representing the processes that are currently subscribed to the given topic.
Specs:
- topics :: [topic]
Returns a list of the current topics.
Specs:
- unsubscribe(pid, topic) :: :ok
Unsubscribes a process from a given topic.
Example
iex> PubSub.unsubscribe(pid, :my_topic)
:ok