ycv005

ycv005

Handling PID of Genserver in params and HTML.eex template

Following is my PID while printing in log

    IO.puts("++++++pid")
    IO.inspect(pid)

as result I am getting

++++++pid
#PID<0.9069.0>

I am pasisng this PID in following ways-
1- inserting into session and render to live view
2- From live view passing it to html
3- Then Html to a controller.
Now, what happens I am getting error as following-

protocol Phoenix.Param not implemented for #PID<0.9069.0>. This protocol is implemented for: Map, BitString, Atom, Integer, Any

Now, I want to pass this PID as I have to used it later on. And to do so, I must ensure that it pass well in params as well as other places. How can I do this? Any help will be appreciated.

Most Liked

NobbZ

NobbZ

Again, you shall not use the pid to send it between client and server, it is not properly deserializable.

You can use though an atom as name for the GenServer though and send it to the client. But this does not scale well.

Better were to use Registry and :via tuples to name the GenServer on start. Then you can send the moving parts of the :via tuple to the client (perhaps a session id or something like that) and reconstruct the tuple on the server.

NobbZ

NobbZ

PIDs are mainly opaque, even though you could send its textual representation to the client, you weren’t be able to get back a PID from it on the server side.

If you really need your client to know the “address” of a certain GenServer, rather than letting the server know which of the running GenServers is responsible for the users session, then use a symbolic name and Registry.

NobbZ

NobbZ

Then you can just use the identifier when calling GenServer.call/GenServer.cast.

Both functions can deal with pids or with whatever :name you gave the GenServer when starting it.

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
_russellb
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
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
vertexbuffer
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
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
joeerl
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

We're in Beta

About us Mission Statement