Zalgorithm

Using Elixir registries to name processes

About Registries #

Registry is the Elixir process registry module. It makes it possible to use any Elixir value to name a process, (as opposed to only being able to use atoms to name processes).

Docs:

Register and access named processes #

Registry.start_link(name: KV, keys: :unique)

Instead of passing an atom to the name option, pass a tuple with the shape {:via, registry_module, {registry_name, process_name}}:

counter = {:via, Registry, {KV, "counter"}}
{:ok, _} = Agent.start_link(fn -> 0 end, name: counter)
Agent.update(counter, & &1 + 1)
Agent.get(counter, & &1)
Tags: