feat(pubsub): add channel registry pub/sub

This commit is contained in:
dualfroz committed 2026-08-26 22:40:00 +02:00
1 parent 6f64fa16d6
commit bac1011429
1 file changed
+14
+14
View File
@@ -0,0 +1,14 @@
defmodule Excache.PubSub do
@moduledoc false
@registry Excache.PubSub.Registry
def subscribe(channel), do: Registry.register(@registry, channel, nil)
def unsubscribe(channel), do: Registry.unregister(@registry, channel)
def publish(channel, payload) do
subscribers = Registry.lookup(@registry, channel)
Enum.each(subscribers, fn {pid, _} -> send(pid, {:pubsub, channel, payload}) end)
length(subscribers)
end
end