<div dir="ltr">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.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 20 Mar 2020 at 08:48, Siyang Zhang <<a href="mailto:zhangsiyang0629725@gmail.com">zhangsiyang0629725@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi</div><div>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 ?</div><div><br></div>Besides, what's the <a href="http://www.baidu.com/link?url=xAnXIoWhmKWFBSQUUyQVGU5R3vYAsHfGPJ2rSVSXGaR1kfiKNXdJxod0EhbZg3jq91oZaxYTc8khhaTLWjSW53tqqPMFmMBEtBfjIqW5q9m" style="color:rgb(51,51,51);text-decoration-line:none;font-size:13px;font-family:arial" target="_blank">annotation</a> mean ?<div><br></div><div>Could anybody help me ? Thanks<br><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"Source Code Pro";font-size:11.3pt"><span style="color:rgb(128,128,128)">%% When/if erlang:monitor() returns before trying to connect to the<br></span><span style="color:rgb(128,128,128)">%% other node this function can be removed.<br></span>do_monitor(<span style="color:rgb(152,118,170)">Pid</span>) -><br> <span style="color:rgb(204,120,50)">case </span>(node(<span style="color:rgb(152,118,170)">Pid</span>) =:= node()) <span style="color:rgb(204,120,50)">orelse </span>lists:member(node(<span style="color:rgb(152,118,170)">Pid</span>), nodes()) <span style="color:rgb(204,120,50)">of<br></span><span style="color:rgb(204,120,50)"> </span>true -><br> <span style="color:rgb(128,128,128)">%% Assume the node is still up<br></span><span style="color:rgb(128,128,128)"> </span>{<span style="color:rgb(152,118,170)">Pid</span>, erlang:monitor(process, <span style="color:rgb(152,118,170)">Pid</span>)};<br> false -><br> <span style="color:rgb(152,118,170)">F </span>= <span style="color:rgb(204,120,50)">fun</span>() -><br> <span style="color:rgb(152,118,170)">Ref </span>= erlang:monitor(process, <span style="color:rgb(152,118,170)">Pid</span>),<br> <span style="color:rgb(204,120,50)">receive<br></span><span style="color:rgb(204,120,50)"> </span>{'DOWN', <span style="color:rgb(152,118,170)">Ref</span>, process, <span style="color:rgb(152,118,170)">Pid</span>, <span style="color:rgb(152,118,170)">_Info</span>} -><br> exit(normal)<br> <span style="color:rgb(204,120,50)">end<br></span><span style="color:rgb(204,120,50)"> end</span>,<br> erlang:spawn_monitor(<span style="color:rgb(152,118,170)">F</span>)<br> <span style="color:rgb(204,120,50)">end.</span></pre></div></div></div>
</blockquote></div>