I am circling around with the following problem and no post helped me so far.
I have a GenServer module named MyApp.Repo
here that runs GenServer.cast
but GenServer.call
returns an error and kills the process.
GenServer MyApp.Repo terminating
** (ArgumentError) unknown registry: MyApp.Repo
When I start the app, I check:
iex> Enum.member?(Process.registered(), MyApp.Repo)
=> true
The GenServer module MyApp.Repo
is supervised as a child by the Application supervisor.
children = [
MyAppWeb.Telemetry,
{Phoenix.PubSub, name: MyApp.PubSub, adapter: Phoenix.PubSub.PG2},
MyApp.Repo,
MyAppWeb.Endpoint
...
MyApp.Repo
module is a basic GenServer that registers a :name
:
def start_link(),
do: GenServer.start_link(__MODULE__, [], name: __MODULE__)
def save_with_cast(user),
do: GenServer.cast(__MODULE__, {:new, user})
def save_with_call(user) do
IO.inspect(user, label: "CALL______")
GenServer.call(__MODULE__, {:new, user})
end
def handle_call({:new, user}, _from,_state) do
IO.puts("CALL______")
Phoenix.PubSub.broadcast_from(MyApp.PubSub, self(), @topic, {:perform_new, user})
{:reply, user, [])
end
def handle_cast({:new, user}, _state) do
Phoenix.PubSub.broadcast_from(MyApp.PubSub, self(), @topic, {:perform_new, user})
{:noreply, []}
end
def handle_info({:perform_new, message}, _state) do
...
MyApp.save_with_cast(user)
runs :ok but not MyApp.save_with_call(user)
.