Skip to content

Instantly share code, notes, and snippets.

@josefrichter
Created June 1, 2020 20:29
Show Gist options
  • Select an option

  • Save josefrichter/9079a71bda1d3e7ade32e2defeacedd4 to your computer and use it in GitHub Desktop.

Select an option

Save josefrichter/9079a71bda1d3e7ade32e2defeacedd4 to your computer and use it in GitHub Desktop.
defmodule Queue do
use GenServer
def start_link(queue, name) do
GenServer.start(__MODULE__, queue, name: name)
end
# GenServer callbacks
def handle_call(:get, _from, [item | queue]) do
{:reply, item, queue}
end
def handle_cast({:add, item}, queue) do
{:noreply, queue ++ [item]}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment