Created
November 17, 2015 17:20
-
-
Save gausby/8b2e379c0bbbff2ee4d0 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 Store do | |
def start_link do | |
Agent.start_link(fn -> %{} end) | |
end | |
def set(pid, key, value) do | |
Agent.update(pid, fn state -> | |
Map.put(state, key, value) | |
end) | |
end | |
def get(pid, key) do | |
Agent.get(pid, fn state -> | |
Map.get(state, key) | |
end) | |
end | |
end | |
{:ok, pid} = Store.start_link | |
Store.set(pid, :foo, "foo") | |
Store.set(pid, :bar, "bar") | |
Store.set(pid, :baz, "baz") | |
{Store.get(pid, :foo), Store.get(pid, :bar)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment