Skip to content

Instantly share code, notes, and snippets.

@aharpole
Created March 9, 2019 00:03
Show Gist options
  • Save aharpole/aa2e2a26d95d9ffcdea58f185ac0d851 to your computer and use it in GitHub Desktop.
Save aharpole/aa2e2a26d95d9ffcdea58f185ac0d851 to your computer and use it in GitHub Desktop.
Simple GenServer with incrementing integer
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