Suppose I create several child processes in an elixir.
defmodule Child do def start(name) do receive do msg -> IO.puts "Message received by #{name}: #{inspect msg}" end end end defmodule Parent do def main do child1 = spawn_link (fn -> Child.start("1") end) child2 = spawn_link (fn -> Child.start("2") end) child3 = spawn_link (fn -> Child.start("3") end) end end
In any case, can I send a message to all the children of my current process (or some other process)?
send_to_children self(), "hello to all children"
As in some cases, can I say that the runtime broadcasts a message to all processes associated with the current process? I could, of course, store all the generated pids in some kind of data structure and iterate over them, but if there is some canonical way to do this, it looks like it will be more efficient and less error prone.
source share