Skip to content

Instantly share code, notes, and snippets.

@mzemel
Last active October 22, 2015 15:38
Show Gist options
  • Save mzemel/9e843bfbe0dbc2776597 to your computer and use it in GitHub Desktop.
Save mzemel/9e843bfbe0dbc2776597 to your computer and use it in GitHub Desktop.
defmodule MyServer do
use GenServer
def handle_call({:plus, number}, _from, current_number) do
new_number = current_number + new_value
{:reply, new_number, new_number}
end
end
{:ok, pid} = GenServer.start_link(MyServer, 10, name: :calculator)
GenServer.call(pid, {:plus, 10})
# 20
GenServer.call(:calculator, :plus)
# 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment