Re: What is "cheaper"?

Nalin Ranjan <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CACE+zkJZDOfjXCqQ6pz02mJNgEh2c6kcvrP8PjqHt8J4V8Qujg@mail.gmail.com>
On Thu, Mar 25, 2021, 5:44 PM Valentin Micic <[email protected]> wrote:

> Hi,
>
> 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.
>
> As an example, consider a following code snippet:
>
> ReqRef = make_ref(),
> SomeServerPid ! {request, {ReqRef, [arg1, arg2, . . ., argn]} ),
> Ref = erlang:send_after( 5000, self(), {cancel, ReqRef} ),
>
> receive
>    {ReqRef, some_reply}
>    ->
>        erlang:cancel_timer(Ref),
>        some_reply
>    ;
>    {cancel, ReqRef}
>    ->
>         “Request Timeout!”
> end
>
> 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.
> As I never really critically examined this claim, is there anyone that may
> have a different opinion regarding this.
>
> 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
>

How do we *ignore* the messages?

generated by send_after/3 instead of canceling it?
>
> Kind regards
>
> V/
>


नमस्ते।
नलिन रंजन
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.