defmodule Utils do def unicast(m, p) do case :global.whereis_name(p) do pid when is_pid(pid) -> send(pid, m) :undefined -> :ok end end def beb_broadcast(m, dest), do: for(p <- dest, do: unicast(m, p)) def register_name(name, pid, link \\ true) do case :global.re_register_name(name, pid) do :yes -> # Note this is running on the parent so we are linking the parent to the rb # so that when we close the parent the rb also dies if link do Process.link(pid) end pid :no -> Process.exit(pid, :kill) :error end end end