process-communication/lib/stack.ex

20 lines
332 B
Elixir
Raw Normal View History

2023-07-03 10:51:47 +00:00
defmodule MyStack do
use GenServer
def start_link(args) do
GenServer.start_link(__MODULE__, nil, name: args[:name])
end
def init(_) do
{:ok, []}
end
def handle_info({:push, el}, state) do
{:noreply, [el] ++ state}
end
def handle_call(:pop, _from, [head | tail]) do
{:reply, head, tail}
end
end