There seems to be quite a bit of overlap between these 3.
1- What are the main differences between:
Channel
, Endpoint
, PubSub
calling broadcast
, broadcast_from
2- They appear to all be built upon PubSub.broadcast
, which a mod in the elixir discord pointed out was sending 2 messages: phoenix_pubsub/pubsub.ex at v2.1.1 · phoenixframework/phoenix_pubsub · GitHub
@spec broadcast_from(t, pid, topic, message, dispatcher) :: :ok | {:error, term}
def broadcast_from(pubsub, from, topic, message, dispatcher \\ __MODULE__)
when is_atom(pubsub) and is_pid(from) and is_binary(topic) and is_atom(dispatcher) do
{:ok, {adapter, name}} = Registry.meta(pubsub, :pubsub)
with :ok <- adapter.broadcast(name, topic, message, dispatcher) do
dispatch(pubsub, from, topic, message, dispatcher)
end
end
Why are both a broadcast
and a dispatch
being called here? And which one is the one that pushes to the socket?
PS: I would like to contribute a PR the docs once I have wrapped my head around the differences