gen_server: `start_monitor/4` 中的 `Mon` 是什么?
gen_server: what is `Mon` in `start_monitor/4`?
OTP 文档说 gen_server:start_monitor/4
的签名是:
start_monitor(ServerName, Module, Args, Options) -> Result
OTP 23.0
Types
ServerName = {local,Name} | {global,GlobalName}
| {via,Module,ViaName}
Name = atom()
GlobalName = ViaName = term()
Module = atom()
Args = term()
Options = [Option]
Option = {debug,Dbgs} | {timeout,Time} | {hibernate_after,HibernateAfterTimeout} | {spawn_opt,SOpts}
Dbgs = [Dbg]
Dbg = trace | log | statistics | {log_to_file,FileName} | {install,{Func,FuncState}}
SOpts = [term()]
Result = {ok,{Pid,Mon}} | ignore | {error,Error}
Pid = pid()
Error = {already_started,Pid} | term()
什么是Mon
?文档只是说:
"Mon is a reference to the monitor set up to monitor the server"
所以现在我知道 Mon
是一个监视器并且它在监视,但它的类型是什么?
阅读erlang.erl
,我发现:
-type registered_name() :: atom().
-type registered_process_identifier() :: registered_name() | {registered_name(), node()}.
-type monitor_process_identifier() :: pid() | registered_process_identifier().
Mon
pid() | atom() | {atom(), node()}
的类型也是这样吗?
Mon
是监控的参考:
monitor_return({{ok, Pid}, Mon}) when is_pid(Pid), is_reference(Mon) ->
%% Successful start_monitor()...
{ok, {Pid, Mon}};
(代码为 here)
OTP 文档说 gen_server:start_monitor/4
的签名是:
start_monitor(ServerName, Module, Args, Options) -> Result
OTP 23.0
Types
ServerName = {local,Name} | {global,GlobalName}
| {via,Module,ViaName}
Name = atom()
GlobalName = ViaName = term()
Module = atom()
Args = term()
Options = [Option]
Option = {debug,Dbgs} | {timeout,Time} | {hibernate_after,HibernateAfterTimeout} | {spawn_opt,SOpts}
Dbgs = [Dbg]
Dbg = trace | log | statistics | {log_to_file,FileName} | {install,{Func,FuncState}}
SOpts = [term()]
Result = {ok,{Pid,Mon}} | ignore | {error,Error}
Pid = pid()
Error = {already_started,Pid} | term()
什么是Mon
?文档只是说:
"Mon is a reference to the monitor set up to monitor the server"
所以现在我知道 Mon
是一个监视器并且它在监视,但它的类型是什么?
阅读erlang.erl
,我发现:
-type registered_name() :: atom().
-type registered_process_identifier() :: registered_name() | {registered_name(), node()}.
-type monitor_process_identifier() :: pid() | registered_process_identifier().
Mon
pid() | atom() | {atom(), node()}
的类型也是这样吗?
Mon
是监控的参考:
monitor_return({{ok, Pid}, Mon}) when is_pid(Pid), is_reference(Mon) ->
%% Successful start_monitor()...
{ok, {Pid, Mon}};
(代码为 here)