<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 16 mar 2014, at 22:29, Anthony Ramine <<a href="mailto:n.oxyde@gmail.com">n.oxyde@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">This sounds like a good idea but with many edge cases.<br><br>For starters, there lack a demonitor call with flush option set in the timeout clause.<br><br></blockquote>Thanks. Missed that one.</div><div><br><blockquote type="cite">Then, from what I understand reading your snippet of code, I gather that the message is only sent once, right?<br><br></blockquote>Well, then plan is/was that UP/DOWN messages are sent as long as the name monitor is till running.</div><div><br><blockquote type="cite">What happens if I call monitor after the name was registered and wait for ‘UP’? Or will it wait for the process to die and the name to be freed to send a ‘DOWN’? In my opinion, this behaves in manner too different from process monitors to reuse the same function.<br><br></blockquote>To get this to work (the way I want) one message must be sent when the monitor(name, x) is created</div><div>to reflect the status of the name registration, DOWN or UP. The demonitor flush will then remove all</div><div>messages matching the Ref. So for "multi shot" version the a demonitor flush is needed in both cases</div><div>since a DOWN message may have been sent if the name was not registered at the creation of the monitor.</div><div><br></div><div><div>wait_for_user_p(N) -></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>Timeout = N*100,</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>Ref = erlang:monitor(name, user),</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>recieve</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>{'UP', Ref, name, Pid, user} -></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>link(Pid),</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>erlang:demonitor(Ref, [flush]),</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>{ok, Pid}</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>after</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>Timeout -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>erlang:demonitor(Ref, [flush]),<span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>{error, nouser}</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>end<span class="Apple-tab-span" style="white-space: pre; "> </span>.</div></div><div><br></div><div>And as you pointed out a "single shot" version could be simpler to understand and </div><div>be more like the normal monitor. 'whereis' must then be called after the monitor</div><div>has been started. The monitor will only send registration changes in this case.</div><div><br></div><div><div>wait_for_user_p(N) -></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>Ref = erlang:monitor(name, user),</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>case whereis(user) of</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Pid when is_pid(Pid) -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>erlang:demonitor(Ref, [flush]),</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>link(Pid),</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{ok, Pid};</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>_ -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Timeout = N*100,</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>recieve</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>{'UP', Ref, name, Pid, user} -></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>link(Pid),</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>{ok, Pid}</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>after</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>Timeout -></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>erlang:demonitor(Ref, [flush]),<span class="Apple-tab-span" style="white-space: pre; "> </span></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>{error, nouser}</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>end</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>end.</div><div><br></div><div>I think that name monitors are not really like process or port monitors, where the death of</div><div>a process or port naturally removes the monitor since there is nothing to monitor.</div><div>The name however will of course continue to exist for ever. I do think </div><div>that the "single shot" version could be acceptable since it solves the problem.</div><div><br></div><div>/Tony</div><div><br></div></div><div><br><blockquote type="cite">-- <br>Anthony Ramine<br><br>Le 16 mars 2014 à 21:26, Tony Rogvall <<a href="mailto:tony@rogvall.se">tony@rogvall.se</a>> a écrit :<br><br><blockquote type="cite"><br>On 16 mar 2014, at 00:21, Tony Rogvall <<a href="mailto:tony@rogvall.se">tony@rogvall.se</a>> wrote:<br><br><blockquote type="cite">I would like to see (and have been for a long time :):<br><br>monitor(name, abc) -> reference()<br><br>and then be able get notifications when the name abc is registered and unregistered.<br><br>Then notifications could be something like:<br><br>{'UP',Ref, name, Pid, abc }<br>{'UP',Ref, name, Port, abc }<br>{'DOWN', Ref, name, Pid, abc}<br>{'DOWN', Ref, name, Port, abc}<br><br></blockquote><br>A comment on my own suggestion:<br><br>The following (ugly) code in user_sup.erl:<br><br>wait_for_user_p(0) -><br> {error, nouser};<br>wait_for_user_p(N) -><br> case whereis(user) of<br><span class="Apple-tab-span" style="white-space:pre"> </span>Pid when is_pid(Pid) -><br><span class="Apple-tab-span" style="white-space:pre"> </span> link(Pid),<br><span class="Apple-tab-span" style="white-space:pre"> </span> {ok, Pid};<br><span class="Apple-tab-span" style="white-space:pre"> </span>_ -><br><span class="Apple-tab-span" style="white-space:pre"> </span> receive after 100 -> ok end,<br><span class="Apple-tab-span" style="white-space:pre"> </span> wait_for_user_p(N-1)<br> end.<br><br>Could then be replace with:<br><br>wait_for_user_p(N) -><br><span class="Apple-tab-span" style="white-space:pre"> </span>Timeout = N*100,<br><span class="Apple-tab-span" style="white-space:pre"> </span>Ref = erlang:monitor(name, user),<br><span class="Apple-tab-span" style="white-space:pre"> </span>recieve<br><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>{'UP', Ref, name, Pid, user} -><br><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>link(Pid),<br><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>{ok, Pid}<br><span class="Apple-tab-span" style="white-space:pre"> </span>after<br><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>Timeout -><br><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>{error, nouser}<br><span class="Apple-tab-span" style="white-space:pre"> </span>end<span class="Apple-tab-span" style="white-space:pre"> </span>.<br><br><br><blockquote type="cite">/Tony<br><br><br>On 14 mar 2014, at 23:50, Loïc Hoguin <<a href="mailto:essen@ninenines.eu">essen@ninenines.eu</a>> wrote:<br><br><blockquote type="cite">Hello,<br><br>I want to discuss monitor/2.<br><br>It's been there for a while, and it's always taking 'process' as first argument. Any plans to add anything else? And if nothing is foreseen before the end of times, any plans to add a monitor/1 instead?<br><br>Thanks.<br><br>-- <br>Loïc Hoguin<br><a href="http://ninenines.eu">http://ninenines.eu</a><br>_______________________________________________<br>erlang-questions mailing list<br>erlang-questions@erlang.org<br>http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote><br>"Installing applications can lead to corruption over time. Applications gradually write over each other's libraries, partial upgrades occur, user and system errors happen, and minute changes may be unnoticeable and difficult to fix"<br><br><br><br>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote><br>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote><br></blockquote></div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px; "><div><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; ">"Installing applications can lead to corruption over time. </span><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; ">Applications gradually write over each other's libraries, partial upgrades occur, user and system errors happen, and minute changes may be unnoticeable and difficult to fix"</span></div><div><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; "><br></span></div></span><br class="Apple-interchange-newline">
</div>
<br></body></html>