Possible to enumerate all entries in a process Registry?

With ample help from the community, I have been exploring some of the functionality of Registry, e.g. to use strings instead of atoms to register processes.

I’m wondering if there’s a way to iterate through every entry in the registry? I guess I’m not following what Registry.dispatch/3 does… I see that somehow the values that are available to the entries are tied to values supplied via Registry.register/3, but I’m having a hard time connecting those dots. I guess I’m trying to squint and see an “Enum” in there, but this isn’t quite that and I’m hoping someone can shed light on why. Thanks for any insights!

You can get a full list with Registry.select, but this is discouraged due to the size of things in the registry may have.

Registry.dispatch is mostly useful with duplicate registries - there’s a short example in the docs. Using it with a Registry that’s used to name processes is likely not what you want.

As @LostKobrakai mentioned, Registry.select is an option - but it’s expensive for large registries, and poorly-defined if the processes in the registry are short-lived. Consider reversing the information flow with pubsub - instead of “get a list of all the Foo processes and then send each one a message”, think “all the Foo processes subscribe to a topic, then publish a message to that topic”.

1 Like

Thank you! This gives me some new ways to think about this.