Skip to content

Add quick Registry example to GenServer docs #14368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add quick Registry example to GenServer docs
  • Loading branch information
nathanl committed Mar 25, 2025
commit fa3e9e8cbda9b5e91fd3aee460e83cf98517d94d
8 changes: 8 additions & 0 deletions lib/elixir/lib/gen_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ defmodule GenServer do
generated atoms won't be garbage-collected. For such cases, you can
set up your own local registry by using the `Registry` module.

For example:

{:ok, _} = Registry.start_link(keys: :unique, name: :stacks)
name = {:via, Registry, {:stacks, "stack 1"}}
{:ok, _pid} = GenServer.start_link(Stack, "hello", name: name)
Registry.lookup(:stacks, "stack 1")
#=> [{#PID<0.150.0>, nil}]

## Receiving "regular" messages

The goal of a `GenServer` is to abstract the "receive" loop for developers,
Expand Down
Loading