fireproofsocks
Naming GenServer using :via does not work the same as naming Agent with :via
I’m working with a custom registry and I’ve noticed that it doesn’t seem to like GenServers. Whereas I can start up an Agent using the same :via clause and things work.
Given this GenServer:
defmodule Replay do
@moduledoc false
use GenServer
@impl true
def init(opts), do: {:ok, opts}
@impl true
def handle_call(request, _from, state), do: {:reply, request, state}
end
I try starting instances of it:
{:ok, _} = Registry.start_link(keys: :unique, name: MyRegistry)
{:ok, _pid} = GenServer.start_link(Replay, name: {:via, Registry, {MyRegistry, "aaa", "v1"}})
{:ok, _pid} = GenServer.start_link(Replay, name: {:via, Registry, {MyRegistry, "ccc", "v3"}})
{:ok, _pid} = GenServer.start_link(Replay, name: {:via, Registry, {MyRegistry, "bbb", "v2"}})
{:ok, _pid} = Agent.start_link(fn -> 0 end, name: {:via, Registry, {MyRegistry, "ddd", "v4"}})
Registry.select(MyRegistry, [{{:"$1", :"$2", :"$3"}, [], [{{:"$1", :"$2", :"$3"}}]}])
# Expected:
[{"aaa", #PID<0.131.0>, "v4"}, {"bbb", #PID<0.132.0>, "v4"}, {"ccc", #PID<0.133.0>, "v4"}, {"ddd", #PID<0.134.0>, "v4"}]
# Actual:
[{"ddd", #PID<0.134.0>, "v4"}]
Can someone explain this? And hopefully point at the error? Thanks in advance!
Marked As Solved
al2o3cr
This is passing name: ... to Replay as opts, GenServer.start_link/3 always needs a second argument. You likely want:
{:ok, _pid} = GenServer.start_link(Replay, [], name: {:via, Registry, {MyRegistry, "aaa", "v1"}})
8
Popular in Questions
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
For example for a current url like
http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2,
I would like to get:
...
New
Hi,
I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Other popular topics
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
Hello everyone,
Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
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









