<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 17 Feb 2021 at 07:07, Lukas Larsson <<a href="mailto:lukas@erlang.org">lukas@erlang.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hello!<div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 16, 2021 at 7:23 PM Guilherme Andrade <<a href="mailto:g@gandrade.net" target="_blank">g@gandrade.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hello list,</div><div><br></div><div>I've spent years writing boilerplate for associating process monitors with other identifiers and react appropriately (and performantly) when one of those processes terminates.<br></div><div><br></div><div>But: what if we could attach data to a monitor and get it back in its DOWN message?</div><div><br></div><div>You'd optionally associate data to a monitor when creating it:<br></div><div>    * Ref = monitor(process, Pid, [{data, {user_id, <<"12345">>}}])</div><div><br></div><div>And you'd get it back upon the monitor being triggered:<br></div><div>    * {'DOWN', Ref, process, Pid, Reason, {user_id, <<"12345">>}}</div><div><br></div><div>Regular monitors would still work the same way and keep the current DOWN message format - nothing would break.</div><div><br></div><div>I've explored this concept using NIFs and published the result to GitHub:<br>    * <a href="https://github.com/g-andrade/vaktari" target="_blank">https://github.com/g-andrade/vaktari</a></div><div><br></div><div>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.<br></div></div></blockquote><div><br></div><div><div>You are in luck!</div><div><br></div><div>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.</div></div></div></div></blockquote><div><br></div><div>This is great news! Can't wait to use it :-)<br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><div><br></div><div>[1]: <a href="https://github.com/erlang/otp/pull/2735" target="_blank">https://github.com/erlang/otp/pull/2735</a></div><div>[2]: <a href="https://github.com/erlang/eep/blob/master/eeps/eep-0053.md" target="_blank">https://github.com/erlang/eep/blob/master/eeps/eep-0053.md</a></div><div>[3]: <a href="https://erlang.org/~rickard/OTP-16718/erts-11.1.1/doc/html/erlang.html#monitor-3" target="_blank">https://erlang.org/~rickard/OTP-16718/erts-11.1.1/doc/html/erlang.html#monitor-3</a></div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div><div><br></div><div>Any input is welcome.</div><div><br></div><div>Cheers!<br></div><div><br>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Guilherme<br></div></div></div></div></div></div></div></div>
</blockquote></div></div>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Guilherme<br></div></div></div></div></div></div></div>