<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 25 Mar 2021, at 14:59, Nalin Ranjan <<a href="mailto:ranjanified@gmail.com" class="">ranjanified@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class=""><div class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 25, 2021, 5:44 PM Valentin Micic <<a href="mailto:v@micic.co.za" class="">v@micic.co.za</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class="">Hi,<div class=""><br class=""></div><div class="">Usually, when I use erlang:send_after/3, but no longer need the “ordered" event, I issue a corresponding erlang:cancel_timer/1 to stop this event from being raised.</div><div class=""><br class=""></div><div class="">As an example, consider a following code snippet:</div><div class=""><br class=""></div><div class=""><span style="font-family:Menlo;font-size:11px" class="">ReqRef = make_ref(),</span></div><div class=""><font face="Menlo" class=""><span style="font-size:11px" class="">SomeServerPid ! {request, {ReqRef, [arg1, arg2, . . ., argn]} ),</span></font></div><div class=""><span style="font-family:Menlo;font-size:11px" class="">Ref = erlang:send_after( 5000, self(), {cancel, ReqRef} ),</span></div><div class=""><span style="font-family:Menlo;font-size:11px" class=""><br class=""></span></div><div class=""><font face="Menlo" class=""><span style="font-size:11px" class="">receive</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size:11px" class=""> {ReqRef, some_reply}</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size:11px" class=""> -></span></font><span style="font-family:Menlo;font-size:11px" class=""> </span></div><div class=""><font face="Menlo" class=""><span style="font-size:11px" class=""> erlang:cancel_timer(Ref),</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size:11px" class=""> some_reply</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size:11px" class=""> ;</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size:11px" class=""> {cancel, ReqRef}</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size:11px" class=""> -></span></font></div><div class=""><font face="Menlo" class=""><span style="font-size:11px" class=""> “Request Timeout!”</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size:11px" class="">end</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size:11px" class=""><br class=""></span></font></div><div class="">This is what I usually do, because I believed that it would be more cost effective to cancel the timer than to ignore the message ordered by send_after/3.</div><div class="">As I never really critically examined this claim, is there anyone that may have a different opinion regarding this.</div><div class=""><br class=""></div><div class="">Put differently, ensuring that no memory leak is possible (due to general nature of the code handling messages), would it be “cheaper" to ignore the message </div></div></blockquote></div></div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">How do we <b class="">ignore</b> the messages?</div><div dir="auto" class=""><br class=""></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div dir="auto" class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class="">generated by send_after/3 instead of canceling it?</div><div class=""><br class=""></div><div class="">Kind regards</div><div class=""><br class=""></div><div class="">V/</div></div></blockquote></div></div><div dir="auto" class=""><br class=""></div><div dir="auto" class=""><br class=""><span style="font-family:sans-serif" class="">नमस्ते।</span><br style="font-family:sans-serif" class=""><span style="font-family:sans-serif" class="">नलिन रंजन</span><br class=""></div><div dir="auto" class=""></div></div>
</div></blockquote></div><div class=""><br class=""></div><div class=""><br class=""></div><div><b class="">How does one ignore a message? </b>Well, one way would be to receive a message, but do nothing with it (e.g. drop it).</div><div>Or at least this is what I meant by it. (Also, I thought that my reference to “no memory leak” would have been sufficient to hint that a receiving process will remove a message from its queue).</div><div><br class=""></div><div>But, Culpa Mea — I should have formulated my question a bit better.</div><div>Thus, let me take another stab at it: <i class=""><b class="">what would be more efficient, canceling the timer (and thus avoiding generation of the message), or letting the send_after/3 generating (and runtime delivering) the message?</b></i></div><div>The answer should be considered relative to the "event ordering" process — will it spend more time canceling the message, or removing generated message from its queue)?</div><div><br class=""></div><div><br class=""></div><blockquote type="cite" class=""><div dir="auto" class=""><div dir="auto" class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word; line-break: after-white-space;"></div></blockquote></div></div></div></blockquote><div class="">Kind regards</div><div class=""><br class=""></div><div class="">V/</div></body></html>