View Source GracefulGenServer behaviour (Graceful GenServer v0.1.3)

Handles init and terminate of genserver.

This wraps GenServer callbacks to provide the functionality.

  • on_init wraps init callback
  • on_exit wraps terminate callback
  • on_msg wraps handle_info callback

The rest of GenServer callbacks are free to use

examples

Examples

defmodule MyApp.Server do
  use GracefulGenServer

  def on_init(init_args) do
    ...
    initial_state
  end

  # optional
  def on_msg(info_msg, state) do
    ...
    {:noreply, new_state} # or any legit handle_info/2 response
  end

  def on_exit(reason, state) do
    ...
  end
end

Link to this section Summary

Link to this section Callbacks

@callback on_exit(reason :: any(), state :: any()) :: any()
@callback on_init(args :: any()) :: any()
Link to this callback

on_msg(msg, state)

View Source (optional)
@callback on_msg(msg :: any(), state :: any()) ::
  {:noreply, new_state}
  | {:noreply, new_state,
     timeout() | :hibernate | {:continue, continue_arg :: term()}}
  | {:stop, reason :: term(), new_state}
when new_state: term()