Created
August 28, 2018 21:07
-
-
Save beerose/e66a6105ef7197bbaed64863194559e5 to your computer and use it in GitHub Desktop.
This file contains 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 Chatty.ChatState do | |
def start_link do | |
Agent.start_link(fn -> %{} end, name: __MODULE__) | |
end | |
def put_message(message) do | |
Agent.update(__MODULE__, &Map.put_new(&1, :os.system_time(:millisecond), message)) | |
end | |
def get_messages() do | |
Agent.get(__MODULE__, &(&1)) |> Map.values | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment