Created
June 1, 2020 20:29
-
-
Save josefrichter/9079a71bda1d3e7ade32e2defeacedd4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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