25 lines
587 B
Elixir
25 lines
587 B
Elixir
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) 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
|
|
Process.link(pid)
|
|
pid
|
|
|
|
:no ->
|
|
Process.exit(pid, :kill)
|
|
:error
|
|
end
|
|
end
|
|
end
|