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,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
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
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
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
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
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
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
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
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









