Re: Semantic Monitors: a proposal

Guilherme Andrade <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CAA5f+NXDFkq1TdVd8eMRGu7EYL4yqdZSKLJSy3V4A8i4a5P_5w@mail.gmail.com>
On Wed, 17 Feb 2021 at 07:07, Lukas Larsson <[email protected]> wrote:

> Hello!
>
>
> On Tue, Feb 16, 2021 at 7:23 PM Guilherme Andrade <[email protected]> wrote:
>
>> Hello list,
>>
>> I've spent years writing boilerplate for associating process monitors
>> with other identifiers and react appropriately (and performantly) when one
>> of those processes terminates.
>>
>> But: what if we could attach data to a monitor and get it back in its
>> DOWN message?
>>
>> You'd optionally associate data to a monitor when creating it:
>>     * Ref = monitor(process, Pid, [{data, {user_id, <<"12345">>}}])
>>
>> And you'd get it back upon the monitor being triggered:
>>     * {'DOWN', Ref, process, Pid, Reason, {user_id, <<"12345">>}}
>>
>> Regular monitors would still work the same way and keep the current DOWN
>> message format - nothing would break.
>>
>> I've explored this concept using NIFs and published the result to GitHub:
>>     * https://github.com/g-andrade/vaktari
>>
>> Is this a good idea? If so, would it be feasible to implement it in OTP?
>> Should there be an EEP first? I'd be willing to contribute to either.
>>
>
> You are in luck!
>
> PR-2735[1] aka EEP-53[2] adds erlang:monitor/3[3] which can be used to do
> what you want. It will be released in Erlang/OTP 24.
>

This is great news! Can't wait to use it :-)



>
> [1]: https://github.com/erlang/otp/pull/2735
> [2]: https://github.com/erlang/eep/blob/master/eeps/eep-0053.md
> [3]:
> https://erlang.org/~rickard/OTP-16718/erts-11.1.1/doc/html/erlang.html#monitor-3
>
>
>>
>> Any input is welcome.
>>
>> Cheers!
>>
>> --
>> Guilherme
>>
>

-- 
Guilherme
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.