pottu
Register process in Registry using :via with two keys
Currently, I register a GenServer process with a unique name in a local register when invoking a start_link/1 function part of it’s API as follows:
def start_link(%{name: lobby_id, visibility: visibility}) do
via_name = {
:via,
Registry,
{LobbyRegistry, lobby_id}
}
GenServer.start_link(__MODULE__, %{name: lobby_id, visibility: visibility}, [name: via_name])
end
In some cases, I would like to register it both via its unique lobby_id as key, but also via another key used by the registry to identify a particular lobby process. It seems one possibility is to register it later on, e.g. in its init/1 callback using Registry.register/3, but I was wondering if its possible to register the process under both keys at the same time, in the above-mentioned start_link/1. If both are possible, is there any reason to prefer one over the other? Any other, better, solutions?
Marked As Solved
benwilson512
It is not possible to do two keys in the start_link call, you’ll need to do it inside init.
Also Liked
LostKobrakai
Yes. Keys of any registered processes are removed once the processes stop. That’s unrelated to how they became successfully registered.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








