Skip to content

Commit fa3e9e8

Browse files
committed
Add quick Registry example to GenServer docs
1 parent 53b7e55 commit fa3e9e8

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+
Registry.lookup(:stacks, "stack 1")
280+
#=> [{#PID<0.150.0>, nil}]
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)