Skip to content

Instantly share code, notes, and snippets.

@motephyr
Last active March 13, 2018 04:37
Show Gist options
  • Save motephyr/d3b95a78de8fb0f8b62459a5c1501e9f to your computer and use it in GitHub Desktop.
Save motephyr/d3b95a78de8fb0f8b62459a5c1501e9f to your computer and use it in GitHub Desktop.
global variable
defmodule Dresser.Worker do
@moduledoc "The store, based on `Agent`."
def start_link do
result = Agent.start_link(fn -> %{} end, name: __MODULE__)
__MODULE__.put(:free_dress, 3)
result
end
@doc "Gets a value"
@spec get(String.t) :: any
def get(key) do
Agent.get(__MODULE__, &Map.get(&1, key))
end
@doc "Puts a value"
@spec put(String.t, any) :: any
def put(key, value) do
Agent.update(__MODULE__, &Map.put(&1, key, value))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment