kdlogan19
Error: Process is not alive while implementing a Stack through genserver
Hello everyone,
I am implementing a stack with Genserver, but I keep getting an error saying there is no process alive. Please go through the code below.
defmodule Stack.Server do
use GenServer
def start(_elements) do
IO.puts "Hello"
GenServer.start_link(__MODULE__, [4,5,"cool"])
end
def init(init_num) do
{:ok, init_num}
end
def handle_call( _from,:pop,[h|t]) do
IO.inspect [h|t]
IO.inspect [t]
IO.puts "handling call"
{:reply, {:ok,h}, t}
end
def handle_cast({:push,value},state) do
IO.inspect value
IO.puts "handling cast"
{:reply, {:ok,value}, [value|state]}
end
def pop(pid) do
IO.puts "Inside popping stack"
IO.inspect pid
GenServer.call(:pops, pid)
end
def push(stack, item) do
IO.puts "Inside pushing stack"
GenServer.cast(stack,{:push,item})
end
end
{:ok, pid} = Stack.Server.start [1,2,3]
Stack.Server.pop(pid)
Stack.Server.push(pid, 10)
Stack.Server.pop(pid)
And the error message says:
Compiling 2 files (.ex)
Hello
Inside popping stack
#PID<0.121.0>
== Compilation error in file lib/stack/server.ex ==
** (exit) exited in: GenServer.call(:pops, #PID<0.121.0>, 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
(elixir) lib/gen_server.ex:999: GenServer.call/3
Thanks a lot in advance
PS: I am a beginner.
Most Liked
peerreynders
Welcome to the forum!
GenServer.call(:pops, pid)
Have a look at GenServer.call/3
While you are there have a look at the GenServer stack example.
2
ityonemo
Double check
- your function parameter order on genserver.call
- your function matching order when you handle :pop
- your atom literals
Later, you’re gonna want to double check the spec on handle_cast.
2
peerreynders
Check the order of the arguments in your handle_call/3 callback function.
1
Popular in Questions
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
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
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
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
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work.
Or rather, not char, but a substr...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Other popular topics
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
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
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
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
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New







