Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lib/elixir/lib/gen_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,28 @@ defmodule GenServer do
{:ok, new_state :: term} |
{:error, reason :: term} when old_vsn: term | {:down, term}

@doc """
Invoked in some cases to retrieve a formatted version of the `GenServer` status.

This callback can be useful to control the *appearance* of the status of the
`GenServer`. For example, it can be used to return a compact representation of
the `GenServers`'s state to avoid having large state terms printed.

* one of `:sys.get_status/1` or `:sys.get_status/2` is invoked to get the
status of the `GenServer`; in such cases, `reason` is `:normal`

* the `GenServer` terminates abnormally and logs an error; in such cases,
`reason` is `:terminate`

`pdict_and_state` is a two-elements list `[pdict, state]` where `pdict` is a
list of `{key, value}` tuples representing the current process dictionary of
the `GenServer` and `state` is the current state of the `GenServer`.
"""
@callback format_status(reason, pdict_and_state :: list) ::
term when reason: :normal | :terminate

@optional_callbacks format_status: 2

@typedoc "Return values of `start*` functions"
@type on_start :: {:ok, pid} | :ignore | {:error, {:already_started, pid} | term}

Expand Down Expand Up @@ -414,7 +436,7 @@ defmodule GenServer do
@doc false
defmacro __using__(_) do
quote location: :keep do
@behaviour :gen_server
@behaviour GenServer

@doc false
def init(args) do
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/test/elixir/module_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ defmodule ModuleTest do
## Attributes

test "reserved attributes" do
assert List.keyfind(ExUnit.Server.__info__(:attributes), :behaviour, 0) == {:behaviour, [:gen_server]}
assert List.keyfind(ExUnit.Server.__info__(:attributes), :behaviour, 0) == {:behaviour, [GenServer]}
end

test "registered attributes" do
Expand Down