I am following the docs and have built a basic channels application that works. However I want to send messages down the channel which originate from another process. Therefore I want to send messages from that other process, to the Phoenix.Channel process. I understand that Phoenix.Channel is built on top of GenServer and so handle_info
will be usable, but how do I find out the Phoenix.Channel PID in the first place, since it is launched independently of my code?
Basically what is the canonical way of handling this situation, ie where outside processes want to communicate with the Phoenix.Channel so as to get it to send their messages to clients? Is the canonical way to get the PID of the Phoenix.Channel, and implement handle_info? If so how do I get the PID? I could write a function that can be called from the third party so:
defmodule HelloWeb.RoomChannel do
use Phoenix.Channel
def my_pid() do
self()
end
And then just call that. But in that case how do I know if my Phoenix.Channel process is running, when I start asking it for its PID at application launch? Can I be sure it’ll be running, and therefore respond to that my_pid() call, before my third party GenServer starts?