Last active
March 13, 2018 04:37
-
-
Save motephyr/d3b95a78de8fb0f8b62459a5c1501e9f to your computer and use it in GitHub Desktop.
global variable
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 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