[Help] Confused by a code snippet of global module
Karl Velicka
karolis.velicka@REDACTED
Fri Mar 20 10:33:38 CET 2020
Seems like connecting to a node that is not in the cluster is a blocking
operation, and this code is trying to avoid blocking the caller on this
connect operation.
On Fri, 20 Mar 2020 at 08:48, Siyang Zhang <zhangsiyang0629725@REDACTED>
wrote:
> 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/a2a4b3e0/attachment.htm>
More information about the erlang-questions
mailing list