From cbc4c8ba13c7f0ab25235a090e7dedea6a3b3022 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Fri, 3 Jan 2025 14:41:48 +0100 Subject: [PATCH] Clarify metadata behavior in Registry :via docs (#14141) --- lib/elixir/lib/registry.ex | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/elixir/lib/registry.ex b/lib/elixir/lib/registry.ex index a3cb6595347..d0ced53e105 100644 --- a/lib/elixir/lib/registry.ex +++ b/lib/elixir/lib/registry.ex @@ -48,9 +48,20 @@ defmodule Registry do {:ok, _} = Registry.start_link(keys: :unique, name: MyApp.Registry) name = {:via, Registry, {MyApp.Registry, "agent", :hello}} {:ok, agent_pid} = Agent.start_link(fn -> 0 end, name: name) + Registry.lookup(MyApp.Registry, "agent") #=> [{agent_pid, :hello}] + name_without_meta = {:via, Registry, {MyApp.Registry, "agent"}} + Agent.update(name_without_meta, fn x -> x + 1 end) + Agent.get(name_without_meta, & &1) + #=> 1 + + > #### With *and* without metadata {: .tip} + > + > When using the version of `:via` tuples with *metadata*, you can still use the version + > **without** metadata to look up the process. + To this point, we have been starting `Registry` using `start_link/1`. Typically the registry is started as part of a supervision tree though: