Skip to content

Commit

Permalink
gen_server: use proc_libs types
Browse files Browse the repository at this point in the history
  • Loading branch information
kikofernandez committed Jun 2, 2023
1 parent 11e9b2c commit 3eb6e8e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 41 deletions.
46 changes: 23 additions & 23 deletions lib/stdlib/doc/src/gen_server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@ gen_server:abcast -----> Module:handle_cast/2
<seemfa marker="#enter_loop/3"><c>enter_loop/3,4,5</c></seemfa>,
and the type
<seetype marker="#server_ref"><c>server_ref()</c></seetype>
below.
is an alias to <seetype marker="stdlib:supervisor#sup_name"><c>supervisor:sup_name()</c></seetype>.
</p>
<taglist>
<tag><c>{local,<anno>LocalName</anno>}</c></tag>
<tag><c>{local,LocalName}</c></tag>
<item>
<p>
Register the <c>gen_server</c> locally
as <c><anno>LocalName</anno></c> using
as <c>LocalName</c> using
<seemfa marker="erts:erlang#register/2">
<c>register/2</c></seemfa>.
</p>
</item>
<tag><c>{global,<anno>GlobalName</anno>}</c></tag>
<tag><c>{global,GlobalName}</c></tag>
<item>
<p>
Register the <c>gen_server</c> process id
Expand All @@ -154,19 +154,19 @@ gen_server:abcast -----> Module:handle_cast/2
<c>global:register_name/2</c></seemfa>.
</p>
</item>
<tag><c>{via,<anno>RegMod</anno>,<anno>ViaName</anno>}</c></tag>
<tag><c>{via,RegMod,ViaName}</c></tag>
<item>
<p>
Register the <c>gen_server</c> process with the registry
represented by <c><anno>RegMod</anno></c>.
The <c><anno>RegMod</anno></c> callback is to export
represented by <c>RegMod</c>.
The <c>RegMod</c> callback is to export
the functions <c>register_name/2</c>, <c>unregister_name/1</c>,
<c>whereis_name/1</c>, and <c>send/2</c>, which are to behave
like the corresponding functions in
<seeerl marker="kernel:global"><c>global</c></seeerl>.
Thus, <c>{via,global,<anno>GlobalName</anno>}</c>
Thus, <c>{via,global,GlobalName}</c>
is a valid reference equivalent to
<c>{global,<anno>GlobalName</anno>}</c>.
<c>{global,GlobalName}</c>.
</p>
</item>
</taglist>
Expand Down Expand Up @@ -197,42 +197,42 @@ gen_server:abcast -----> Module:handle_cast/2
The <c>gen_server</c>'s process identifier.
</p>
</item>
<tag><c><anno>LocalName</anno></c></tag>
<tag><c>LocalName</c></tag>
<item>
<p>
The <c>gen_server</c> is locally registered
as <c><anno>LocalName</anno></c> with
as <c>LocalName</c> with
<seemfa marker="erts:erlang#register/2">
<c>register/2</c></seemfa>.
</p>
</item>
<tag><c>{<anno>Name</anno>,<anno>Node</anno>}</c></tag>
<tag><c>{Name,Node}</c></tag>
<item>
<p>
The <c>gen_server</c> is locally registered
on another node.
</p>
</item>
<tag><c>{global,<anno>GlobalName</anno>}</c></tag>
<tag><c>{global,GlobalName}</c></tag>
<item>
<p>
The <c>gen_server</c> is globally registered in
<seeerl marker="kernel:global"><c>global</c></seeerl>.
</p>
</item>
<tag><c>{via,<anno>RegMod</anno>,<anno>ViaName</anno>}</c></tag>
<tag><c>{via,RegMod,ViaName}</c></tag>
<item>
<p>
The <c>gen_server</c> is registered in
an alternative process registry.
The registry callback module <c><anno>RegMod</anno></c>
The registry callback module <c>RegMod</c>
is to export functions
<c>register_name/2</c>, <c>unregister_name/1</c>,
<c>whereis_name/1</c>, and <c>send/2</c>,
which are to behave like the corresponding functions in
<seeerl marker="kernel:global"><c>global</c></seeerl>.
Thus, <c>{via,global,<anno>GlobalName</anno>}</c>
is the same as <c>{global,<anno>GlobalName</anno>}</c>.
Thus, <c>{via,global,GlobalName}</c>
is the same as <c>{global,GlobalName}</c>.
</p>
</item>
</taglist>
Expand All @@ -248,7 +248,7 @@ gen_server:abcast -----> Module:handle_cast/2
<seemfa marker="#start_link/3"><c>start_link/3,4</c></seemfa>.
</p>
<taglist>
<tag><c>{timeout,<anno>Timeout</anno>}</c></tag>
<tag><c>{timeout,Timeout}</c></tag>
<item>
<p>
How many milliseconds the <c>gen_server</c> process is allowed
Expand All @@ -257,11 +257,11 @@ gen_server:abcast -----> Module:handle_cast/2
</p>
</item>
<tag>
<c>{spawn_opt,<anno>SpawnOptions</anno>}</c>
<c>{spawn_opt,SpawnOptions}</c>
</tag>
<item>
<p>
The <c><anno>SpawnOptions</anno></c> option list
The <c>SpawnOptions</c> option list
is passed to the function used to spawn
the <c>gen_server</c>; see
<seemfa marker="erts:erlang#spawn_opt/2">
Expand Down Expand Up @@ -298,7 +298,7 @@ gen_server:abcast -----> Module:handle_cast/2
<seemfa marker="#start_link/3"><c>start_link/3,4</c></seemfa>.
</p>
<taglist>
<tag><c>{hibernate_after,<anno>HibernateAfterTimeout</anno>}</c></tag>
<tag><c>{hibernate_after,HibernateAfterTimeout}</c></tag>
<item>
<p>
Specifies that the <c>gen_server</c> process awaits
Expand All @@ -309,10 +309,10 @@ gen_server:abcast -----> Module:handle_cast/2
<c>proc_lib:hibernate/3</c></seemfa>).
</p>
</item>
<tag><c>{debug,<anno>Dbgs</anno>}</c></tag>
<tag><c>{debug,Dbgs}</c></tag>
<item>
<p>
For every entry in <c><anno>Dbgs</anno></c>,
For every entry in <c>Dbgs</c>,
the corresponding function in
<seeerl marker="sys"><c>sys(3)</c></seeerl> is called.
</p>
Expand Down
29 changes: 11 additions & 18 deletions lib/stdlib/src/gen_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
reply_tag/0,
request_id/0,
request_id_collection/0,
response_timeout/0,
format_status/0]).

-export_type(
Expand Down Expand Up @@ -246,25 +247,17 @@
%%% -----------------------------------------------------------------

-type server_name() :: % Duplicate of gen:emgr_name()
{'local', LocalName :: atom()}
| {'global', GlobalName :: term()}
| {'via', RegMod :: module(), ViaName :: term()}.

-type server_ref() :: % What gen:call/3,4 and gen:stop/1,3 accepts
pid()
| (LocalName :: atom())
| {Name :: atom(), Node :: atom()}
| {'global', GlobalName :: term()}
| {'via', RegMod :: module(), ViaName :: term()}.

-type start_opt() :: % Duplicate of gen:option()
{'timeout', Timeout :: timeout()}
| {'spawn_opt', SpawnOptions :: [proc_lib:spawn_option()]}
| enter_loop_opt().
proc_lib:sup_name().

% What gen:call/3,4 and gen:stop/1,3 accepts
-type server_ref() :: proc_lib:sup_ref().

% Duplicate of gen:option()
-type start_opt() ::
proc_lib:option() | enter_loop_opt().
%%
-type enter_loop_opt() :: % Some gen:option()s works for enter_loop/*
{'hibernate_after', HibernateAfterTimeout :: timeout()}
| {'debug', Dbgs :: [sys:debug_option()]}.
% Some gen:option()s works for enter_loop/*
-type enter_loop_opt() :: proc_lib:enter_loop_opt().

-type start_ret() :: % gen:start_ret() without monitor return
{'ok', Pid :: pid()}
Expand Down

0 comments on commit 3eb6e8e

Please sign in to comment.