Skip to content

Commit 1c05790

Browse files
nathanljosevalim
andauthored
Add quick Registry example to GenServer docs (#14368)
Co-authored-by: José Valim <[email protected]>
1 parent 3e22d20 commit 1c05790

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/elixir/lib/gen_server.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ defmodule GenServer do
271271
generated atoms won't be garbage-collected. For such cases, you can
272272
set up your own local registry by using the `Registry` module.
273273
274+
For example:
275+
276+
{:ok, _} = Registry.start_link(keys: :unique, name: :stacks)
277+
name = {:via, Registry, {:stacks, "stack 1"}}
278+
{:ok, _pid} = GenServer.start_link(Stack, "hello", name: name)
279+
GenServer.whereis(name)
280+
#=> #PID<0.150.0>
281+
274282
## Receiving "regular" messages
275283
276284
The goal of a `GenServer` is to abstract the "receive" loop for developers,

0 commit comments

Comments
 (0)