Semantic Monitors: a proposal

Max Lapshin max.lapshin@REDACTED
Wed Feb 17 16:32:17 CET 2021


Excellent feature!

On Wed, Feb 17, 2021 at 10:07 AM Lukas Larsson <lukas@REDACTED> wrote:
>
> Hello!
>
>
> On Tue, Feb 16, 2021 at 7:23 PM Guilherme Andrade <g@REDACTED> 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.
>
> [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


More information about the erlang-questions mailing list