Simplified PubSub for Dala apps using Elixir's built-in Registry.
No Redis, no adapters — just fast local pubsub for screens to communicate.
Usage
# In your app's supervision tree:
children = [
{Dala.PubSub, name: MyApp.PubSub}
]
# Subscribe to topics:
Dala.PubSub.subscribe(MyApp.PubSub, "user:123")
# Broadcast messages:
Dala.PubSub.broadcast(MyApp.PubSub, "user:123", {:update, %{id: 123}})
Summary
Functions
Broadcasts a message to all subscribers of a topic.
Broadcasts a message to all subscribers except the sender.
Returns a child specification for pubsub with the given options.
Starts a PubSub instance.
Subscribes the caller to a topic.
Returns the number of subscribers for a topic.
Returns all topics with at least one subscriber.
Unsubscribes the caller from a topic.
Types
Functions
Broadcasts a message to all subscribers of a topic.
Dala.PubSub.broadcast(MyApp.PubSub, "user:123", {:update, data})
Broadcasts a message to all subscribers except the sender.
Dala.PubSub.broadcast_from(MyApp.PubSub, self(), "user:123", {:update, data})
@spec child_spec(keyword()) :: Supervisor.child_spec()
Returns a child specification for pubsub with the given options.
Required option:
:name- the name of the pubsub instance
Starts a PubSub instance.
Options
:name- the name of the pubsub instance (required)
Subscribes the caller to a topic.
Dala.PubSub.subscribe(MyApp.PubSub, "user:123")
@spec subscriber_count(t(), topic()) :: non_neg_integer()
Returns the number of subscribers for a topic.
Returns all topics with at least one subscriber.
Unsubscribes the caller from a topic.
Dala.PubSub.unsubscribe(MyApp.PubSub, "user:123")