[Help] Confused by a code snippet of global module

Siyang Zhang zhangsiyang0629725@REDACTED
Fri Mar 20 09:41:30 CET 2020


Hi
I'm confused by the code snippet of global module. When the 'case clause'
matches false, why use spawn_monitor ? Use erlang:monitor could be wrong ?
Why ?

Besides, what's the annotation
<http://www.baidu.com/link?url=xAnXIoWhmKWFBSQUUyQVGU5R3vYAsHfGPJ2rSVSXGaR1kfiKNXdJxod0EhbZg3jq91oZaxYTc8khhaTLWjSW53tqqPMFmMBEtBfjIqW5q9m>
mean
?

Could anybody help me ? Thanks

%% When/if erlang:monitor() returns before trying to connect to the
%% other node this function can be removed.
do_monitor(Pid) ->
    case (node(Pid) =:= node()) orelse lists:member(node(Pid), nodes()) of
        true ->
            %% Assume the node is still up
            {Pid, erlang:monitor(process, Pid)};
        false ->
            F = fun() ->
                Ref = erlang:monitor(process, Pid),
                receive
                    {'DOWN', Ref, process, Pid, _Info} ->
                        exit(normal)
                end
                end,
            erlang:spawn_monitor(F)
    end.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200320/132bb441/attachment.htm>


More information about the erlang-questions mailing list