Skip to content

Instantly share code, notes, and snippets.

@beerose
Created August 28, 2018 21:07
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 beerose/e66a6105ef7197bbaed64863194559e5 to your computer and use it in GitHub Desktop.
Save beerose/e66a6105ef7197bbaed64863194559e5 to your computer and use it in GitHub Desktop.
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