GenServer.start_link
start_link, go back to GenServer module for more information.
Specs
Starts a GenServer process linked to the current process.
This is often used to start the GenServer as part of a supervision tree.
Once the server is started, the init/1 function of the given module is
called with init_arg as its argument to initialize the server. To ensure a
synchronized start-up procedure, this function does not return until init/1
has returned.
Note that a GenServer started with start_link/3 is linked to the
parent process and will exit in case of crashes from the parent. The GenServer
will also exit due to the :normal reasons in case it is configured to trap
exits in the init/1 callback.
Options
:name- used for name registration as described in the "Name registration" section in the documentation forGenServer:timeout- if present, the server is allowed to spend the given number of milliseconds initializing or it will be terminated and the start function will return{:error, :timeout}:debug- if present, the corresponding function in the:sysmodule is invoked:spawn_opt- if present, its value is passed as options to the underlying process as inProcess.spawn/4:hibernate_after- if present, the GenServer process awaits any message for the given number of milliseconds and if no message is received, the process goes into hibernation automatically (by calling:proc_lib.hibernate/3).
Return values
If the server is successfully created and initialized, this function returns
{:ok, pid}, where pid is the PID of the server. If a process with the
specified server name already exists, this function returns
{:error, {:already_started, pid}} with the PID of that process.
If the init/1 callback fails with reason, this function returns
{:error, reason}. Otherwise, if it returns {:stop, reason}
or :ignore, the process is terminated and this function returns
{:error, reason} or :ignore, respectively.