Virviil

Virviil

It’s very easy to supervise :simple_one_for_one children with Registry. The Registry is unique, and via tuple works very good.
But the question is: How to dispatch to all these children?
It seems to me, that is possible to dispatch only to duplicate registry!
Why it’s not possible to list all registered in Registry pid’s?

The workaround is - using Supervisor.which_children get all pids and dispatch messages to them. But it looks a bit rusty.

Showing Posts 1 to 4

Ankhers

Ankhers

Have you taken a look at the Using as a dispatcher section of the documentation? If that still doesn’t answer your question, can you give a bit more information about what you are trying to do?

sasajuric

sasajuric

Author of Elixir In Action

You could use Registry.match/3 for that:

Registry.start_link(:unique, MyRegistry)
Registry.register(MyRegistry, :foo, nil)
spawn(fn -> Registry.register(MyRegistry, :bar, nil); :timer.sleep(:infinity) end)
Registry.match(MyRegistry, :_, :_)
# [{#PID<0.80.0>, nil}, {#PID<0.86.0>, nil}]

However, I feel that it’s better to have another (:duplicate) registry for dispatching. The unique registry should be used when you want to find a particular process which plays some role in your system. The duplicate registry should be used when you want to dispatch to a group of processes. Those are two different needs, so I believe that using different registries describes the idea more explicitly. For what it’s worth, this is how I’d do it myself. If a process needs to be uniquely found, but also belongs to some process group, I’d register it with two registries.

Virviil

Virviil OP

Two registeries is great idea as for me from the point of good architect. I thought about it.

But the problem is with consistency:

Registration in duplicate registry is doing manualy, as I understand. For example, in init function:

def init(_) do
  Registry.register(MyRegistry, "worker_class_name", "my_worker_name")
end

But if the supervisor restarts the simple_one_for_one worker after failure, PID is updated in only uniq register.

So, as I understand, init should be rewrited in such manner:

def init(_) do
  # check here, that registry already have entry with such name, and if not
  Registry.register(MyRegistry, "worker_class_name", "my_worker_name")
  # and if yes - firstly remove that entry, but hard to understand how, and then
  Registry.register(MyRegistry, "worker_class_name", "my_worker_name")
end

So, may be there are some recipes of doing this already? Or may be Registry need some additional functionality? Or even, may be my approach is totally wrong.

sasajuric

sasajuric

Author of Elixir In Action

It’s going to work fine for both registries. If the process terminates, it’s deregistered from all the registries. When the new process is started, it will be properly registered with both registries. You don’t need to check whether the process is already registered, nor remove it from the registry manually.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews