Skip to content

Instantly share code, notes, and snippets.

@josefrichter
Created June 1, 2020 20:24
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 josefrichter/081784490c4947b2b0a8293a3897545a to your computer and use it in GitHub Desktop.
Save josefrichter/081784490c4947b2b0a8293a3897545a to your computer and use it in GitHub Desktop.
defmodule Counter do
use Agent
def start_link(initial_value) do
Agent.start_link(fn -> initial_value end, name: __MODULE__)
end
def value do
Agent.get(__MODULE__, & &1)
end
def increment do
Agent.update(__MODULE__, &(&1 + 1))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment