Skip to content

Instantly share code, notes, and snippets.

@josefrichter
Created June 1, 2020 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josefrichter/b38cb4cfec6505ea3c6fd9615d8deea7 to your computer and use it in GitHub Desktop.
Save josefrichter/b38cb4cfec6505ea3c6fd9615d8deea7 to your computer and use it in GitHub Desktop.
defmodule QueueAgent do
def start_link(queue, name) do
Agent.start_link(fn -> queue end, name: name)
end
def add(queue, item) do
Agent.cast(queue, fn(state) -> state ++ [item] end)
end
def get(queue) do
Agent.get_and_update(queue, fn([item | state]) -> {item, state} end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment