Skip to content

Commit cbc4c8b

Browse files
authored
Clarify metadata behavior in Registry :via docs (#14141)
1 parent bde9494 commit cbc4c8b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/elixir/lib/registry.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,20 @@ defmodule Registry do
4848
{:ok, _} = Registry.start_link(keys: :unique, name: MyApp.Registry)
4949
name = {:via, Registry, {MyApp.Registry, "agent", :hello}}
5050
{:ok, agent_pid} = Agent.start_link(fn -> 0 end, name: name)
51+
5152
Registry.lookup(MyApp.Registry, "agent")
5253
#=> [{agent_pid, :hello}]
5354
55+
name_without_meta = {:via, Registry, {MyApp.Registry, "agent"}}
56+
Agent.update(name_without_meta, fn x -> x + 1 end)
57+
Agent.get(name_without_meta, & &1)
58+
#=> 1
59+
60+
> #### With *and* without metadata {: .tip}
61+
>
62+
> When using the version of `:via` tuples with *metadata*, you can still use the version
63+
> **without** metadata to look up the process.
64+
5465
To this point, we have been starting `Registry` using `start_link/1`.
5566
Typically the registry is started as part of a supervision tree though:
5667

0 commit comments

Comments
 (0)