GenServer.Proxy (GenServer Proxy v0.1.17) 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.

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.

The given module (or by default <caller's_module>.Callback) must implement the 2 callbacks of GenServer.Proxy.Behaviour.

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

stop(reason, server_id, module \\ nil)

View Source (macro)