Created
June 1, 2020 20:30
-
-
Save josefrichter/b38cb4cfec6505ea3c6fd9615d8deea7 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 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