Umbra v0.0.3 Umbra.Extension.NameSetter behaviour View Source
The extension Umbra.Extension.NameSetter
is used to manage the
GenServer name option.
It overrides the Umbra.GenServer.__start__/3
callback to set the process name (only if missing from options)
before starting the GenServer
.
This extension define a callback __get_process_name__/1
to retrieve/set name
depending of the state when start_link/2
or start/2
of your GenServer are called.
Example:
defmodule MyGenServer do
defstruct [:id, :other_states]
use Umbra.GenServer
use Umbra.Extension.NameSetter
@impl Umbra.Extension.NameSetter
def __get_process_name__(%__MODULE__{id: id}) do
{:ok, "MyGenServer::#{id}"}
end
# your code
end
Link to this section Summary
Functions
This macro is used to create a fallback for __get_process_name__/1
callback.
This macro allow setting an override to the Umbra.GenServer.__start__/3
callback and
define a __get_process_name__/1
callback fallback thanks to __before_compile__/1
.
Callbacks
This callback is used to retrieve the process name depending of the parameter.
Link to this section Functions
This macro is used to create a fallback for __get_process_name__/1
callback.
This macro allow setting an override to the Umbra.GenServer.__start__/3
callback and
define a __get_process_name__/1
callback fallback thanks to __before_compile__/1
.
Link to this section Callbacks
Specs
This callback is used to retrieve the process name depending of the parameter.
It always returns {:ok, nil}
except if extensions are used.
The Umbra.Extension.Registry
extension did set this callback to
create the process name from the state thanks to a Registry
(also called a via_name
).
You have to take care of the declaration orders.