GenServer Proxy v0.1.4 GenServer.Proxy View Source
Link to this section Summary
Functions
Performs a GenServer call.
Will wait a bit if the server is not yet registered on restarts.
A module
to implement the 2 callbacks of GenServer.Proxy.Behaviour
is required and its default name is <caller's module>.Callback
Link to this section Functions
Link to this macro
call(request, server_id, module \\ nil) View Source (macro)
Performs a GenServer call.
Will wait a bit if the server is not yet registered on restarts.
A module
to implement the 2 callbacks of GenServer.Proxy.Behaviour
is required and its default name is <caller's module>.Callback
.
Examples
# Assuming the following callback module:
defmodule Game.Engine.Callback do
@behaviour GenServer.Proxy.Behaviour
@impl GenServer.Proxy.Behaviour
def server_name(game_name),
do: {:via, Registry, {:registry, game_name}}
@impl GenServer.Proxy.Behaviour
def server_unregistered(game_name),
do: IO.puts("Game #{game_name} not started.")
end
# We could use the call macro like so:
defmodule Game.Engine do
use GenServer.Proxy
def summary(game_name), do: call(:summary, game_name)
...
end
Link to this macro
cast(request, server_id, module \\ nil) View Source (macro)
Link to this macro