<div dir="ltr">> <span style="font-size:12.8px">supervisor:which_children/1</span><div><span style="font-size:12.8px">> Is the the best way? - does anybody have an example?</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">That and using erlang:process_info(Pid, links) are the only ways.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">The supervisor module lacks a child(SupRef, Name) function that would now be able to fetch children by Name</span></div><div><span style="font-size:12.8px">with a complexity better than O(n) now that the module can use maps.</span></div><div><span style="font-size:12.8px">I started writing a PR for that but then got confused by the code that can either use sets or maps: </span><span style="font-size:12.8px">I couldn't understand which backend would be used when...</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">My use case is to not register names for child processes (using erlang:register via {local,Name}).</span></div><div><span style="font-size:12.8px"><br></span></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div><br></div><div>Cheers,</div><div>-- </div><div>Pierre Fenoll</div></div><div><br></div></div></div></div>
<br><div class="gmail_quote">On 7 December 2017 at 14:26, Vance Shipley <span dir="ltr"><<a href="mailto:vances@motivity.ca" target="_blank">vances@motivity.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Thu, Dec 7, 2017 at 6:03 PM, Joe Armstrong <<a href="mailto:erlang@gmail.com">erlang@gmail.com</a>> wrote:<br>
> I was asked the following in a direct mail to me:<br>
><br>
> "Given two worker processes in a supervision tree, A and B, if A wants<br>
> to message B, how should it obtain the pid of B ?"<br>
><br>
> Pretty good question.<br>
><br>
> I think the answer is to use supervisor:which_children/1 and to name<br>
> the supervisor and all the children.<br>
><br>
> Is the the best way? - does anybody have an example?<br>
<br>
</span>Sure, I don't bother to name the supervisor though, pass the pid() down:<br>
<br>
Here's an example of a gen_server which locates it's sibling<br>
simple_one_for_one supervisors after initializing:<br>
<a href="https://github.com/sigscale/ocs/blob/8aafd48fd876b7434517b512d79d2c12559889bb/src/ocs_radius_auth_port_server.erl#L157" rel="noreferrer" target="_blank">https://github.com/sigscale/<wbr>ocs/blob/<wbr>8aafd48fd876b7434517b512d79d2c<wbr>12559889bb/src/ocs_radius_<wbr>auth_port_server.erl#L157</a><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
-Vance<br>
</font></span><div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div>