feat(pubsub): add channel registry pub/sub
This commit is contained in:
1 parent
6f64fa16d6
commit
bac1011429
1 file changed
+14
@@ -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
|
||||||
Reference in new issue
Block a user