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

publish(topic, message)

Specs:

Delivers a message to the given topic.

Example

iex> PubSub.publish(:my_topic, "Hi there!")
:ok
start_link()

Starts the server.

subscribe(pid, topic)

Specs:

  • subscribe(pid, topic) :: :ok

Subscribes a process to the given topic.

Example

iex> PubSub.subscribe(pid, :my_topic)
:ok
subscribers(topic)

Specs:

  • subscribers(topic) :: [pid]

Returns a list of pids representing the processes that are currently subscribed to the given topic.

topics()

Specs:

Returns a list of the current topics.

unsubscribe(pid, topic)

Specs:

  • unsubscribe(pid, topic) :: :ok

Unsubscribes a process from a given topic.

Example

iex> PubSub.unsubscribe(pid, :my_topic)
:ok