I have an endpoint /rooms/:room_code
that looks up a value in an Elixir Registry based on the value of room_code, using the following code
def get_room(room_code) do
name = {:via, Registry, {Coordinator.Rooms, room_code}}
{:ok, Agent.get(name, & &1)}
end
If I enter localhost:4000/rooms/abcd
it works fine, and it finds the room. However, if I use the following from a different LiveView
def handle_event("redirect", _, socket) do
{:noreply, socket
|> push_redirect(to: Routes.room_show_path(socket, :show, socket.assigns.room_code))}
end
I get the error
[error] GenServer #PID<0.658.0> terminating
** (stop) exited in: GenServer.call({:via, Registry, {Coordinator.Rooms, "abcd"}}, {:get, #Function<4.87964163/1 in Skg.Edge.Coordinator.get_room/1>}, 5000)
** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
It’s probably something basic that I’m not understanding about LiveView lifecycles or something, but I’m having a hard time finding information on it. Anyone know why this is happening? Thanks in advance.