Xgit v0.1.0 Xgit.Util.GenServerUtils

Some utilities to make error handling in GenServer calls easier.

Xgit is somewhat more exception-friendly than typical Elixir code.

Link to this section Summary

Functions

Makes a synchronous call to the server and waits for its reply.

Delegate a handle_call/3 call to a handle_(something) call on a module.

Wrap a handle_call/3 call to a handle_(something) call on a module.

Link to this section Functions

Link to this function

call!(server, request, timeout \\ 5000)
call!(
  server :: GenServer.server(),
  request :: term(),
  timeout :: non_neg_integer()
) :: term()

Makes a synchronous call to the server and waits for its reply.

Return Value

If the response is :ok, return server (for function chaining).

If the response is {:ok, (value)}, return value.

If the response is {:error, (reason)}, raise reason as an error.

Link to this function

delegate_call_to(mod, function, args, mod_state)
delegate_call_to(
  mod :: module(),
  function :: atom(),
  args :: term(),
  mod_state :: term()
) :: {:reply, term(), {module(), term()}}

Delegate a handle_call/3 call to a handle_(something) call on a module.

Wraps common :ok and error responses and exceptions and returns them to caller.

Unlike wrap_call/4, assumes that the GenServer state is a tuple of {module, mod_state} and re-wraps module state accordingly.

Link to this function

wrap_call(mod, function, args, prev_state)
wrap_call(
  mod :: module(),
  function :: atom(),
  args :: term(),
  prev_state :: term()
) :: {:reply, term(), term()}

Wrap a handle_call/3 call to a handle_(something) call on a module.

Wraps common :ok and error responses and exceptions and returns them to caller.

Should be used for standalone modules (i.e. modules that are not open to extension).