Created
March 9, 2019 00:03
-
-
Save aharpole/aa2e2a26d95d9ffcdea58f185ac0d851 to your computer and use it in GitHub Desktop.
Simple GenServer with incrementing integer
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 IncrementableValue do | |
use GenServer | |
def start_link() do | |
GenServer.start_link(__MODULE__, []) | |
end | |
def init(_) do | |
{:ok, 1} | |
end | |
def handle_call(:get_data, _, state) do | |
{:reply, state, state} | |
end | |
def handle_cast(:increment, state) do | |
{:noreply, state + 1} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment