Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Elixir XGen GenServer semantics discussion
defmodule FooServer do
@behaviour :gen_server
@server_name {:global, :foo_server}
# Client
def do_it do
try do
:gen_server.call @server_name, :foo
catch
:exit, reason -> {:error, reason}
end
end
def do_it! do
:gen_server.call @server_name, :foo
end
# Server
def start do
:gen_server.start_link(@server_name, __MODULE__, [], [])
end
def init(args) do
{:ok, args}
end
def handle_call(msg, _from, state) do
:timer.sleep(10000)
{:reply, {:ok, :my_response}, state}
end
def handle_info(msg, state) do
{:noreply, state}
end
def handle_cast(msg, state) do
{:stop, {:bad_cast, msg}, state}
end
def terminate(_reason, _state) do
:ok
end
def code_change(_old, state, _extra) do
{:ok, state}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment