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
Last Post!
ityonemo
I know some languages are more permissive, but elixir is sane, you can’t do def subtract(a, b) with an unexpected matching order.
0
Popular in Questions
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
I would like to know what is the best IDE for elixir development?
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
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
Other popular topics
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









