I have an application that spawns an arbitrary number of processes (little processes) under a supervisor, and a single other process (registered with name BigProcess) that would like to know when new little processes start or if they end.
I looked at Registry and noticed the listeners option, and since my little processes all start using :via tuples to a local registry, I thought maybe that would work for me. So I added
{Registry, keys: :unique, name: LittleProcessRegistry, listeners: [BigProcess]
to my supervisor tree, but I get an error
:erlang.send(BigProcess, {:register, LittleProcessRegistry, LittleProcess.Name, #PID<0.291.0>, nil})
This is (I assume) because the Registry tries to immediately start sending notifications to the big process but it hasn’t finished starting up yet. But I can’t find a way to set the listener after it has started.
Am I misunderstanding how this is meant to be used? Or maybe there’s a better way to do this?