I propose the addition of a function for getting all the keys (and values 
associated with them) out of a registry. Currently the only way of doing that 
is knowing all the pids or keys, and looping over them to request the rest of 
the information from the registry, which is awkward and under-performant.

I came across the need for functionality like this when I was setting up an 
architecture where an outside source, a list of keys, should be used to 
determine what processes to run. For each key in that list a process should be 
started. Over time, the list will change, and the processes running should be 
adjusted to represent this. Assuming there's a DynamicSupervisor owning the 
workers and a coordinating process starting and stopping them, I need a list of 
the current running processes and their keys to compare with the latest version 
of the external state.

A simple solution to the problem would be to rely on the changes between the 
latest version of the list and the last version, and trust the supervisor to 
restart dying processes. This, however, means the workers can't be 
`:temporary`, because we would risk reality getting out of sync of the list of 
workers on the coordinator. But even if I go for `:transient` workers, I still 
risk getting out of sync if the DynamicSupervisor crashes. Even if I keep that 
process clean to avoid crashes, some worker crashing repeatedly can still bring 
it down, and all the workers with it. At that point, the only way to 
synchronize back to the correct state would be restarting the server or 
implement some complex code where the coordinator attempts to verify the status 
of each key by looking it up in the registry, but then we're back to 
inefficiently getting all keys.

I propose a function that looks and works something like this (naming and 
ordering of return values is obviously up for discussion)

```
Registry.all(MyRegistry)
=> [{key, pid, value}, {key, pid, value}, ...]
```

Just like `Registry.count/1` has a corresponding `Registry.count_match/{3,4}`, 
it could be designed to take a match specification.

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/f306261b-7502-4568-a822-18d61217cb1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to