<div dir="ltr"><font face="courier new, monospace">Hi,</font><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">I'm using a supervision tree to manage multiple sets of gen_servers. I've got a situation where gen_servers in one supervision tree (e.g., Tree-B) are clients of gen_servers in another supervision tree (e.g., Tree-A). I'd like Tree-A and all of it's children to complete their initialization processing before starting any of the children in Tree-B.</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> Root Supervisor</font></div><div><font face="courier new, monospace"> |</font></div>
<div><font face="courier new, monospace"> ----------------------------------</font></div><div><font face="courier new, monospace"> | |</font></div><div><font face="courier new, monospace"> Supervisor-A Supervisor-B</font></div>
<div><font face="courier new, monospace"> | |</font></div><div><span style="font-family:'courier new',monospace"> ----------------- -------------</span></div>
<div><font face="courier new, monospace"> | | | | |</font></div><div><font face="courier new, monospace"> 1 2 3 4 5</font></div><div>
<font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">So given this diagram, A and its children 1,2 and 3 start and complete initialization before B and children 4 and 5 are started and complete initialization. Furthermore, initialization in this case means that in module:init/1 the child casts itself a message to complete initialization. E.g., </font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> ...</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"> init([]) -> </font></div>
<div><font face="courier new, monospace"> gen_server:cast(?MODULE, complete_initialization),</font></div><div><font face="courier new, monospace"> {ok, []}.</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"> ... </font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">During Child 4's initialization it calls a function on Child 1 (which has an init/1 implementation as described above).</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">In reading <a href="http://www.erlang.org/doc/man/supervisor.html#start_link-2">http://www.erlang.org/doc/man/supervisor.html#start_link-2</a> I understand that Supervisor-A and all it's children will be started and available before Supervisor-B and its children are started. It's also my understanding that when a child casts itself a message in its init/1 function that that message is guaranteed to be the first message in its mailbox. Is my understanding of this correct and if so, is this a reasonable way to do what I'm trying to accomplish?</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">Thanks,</font></div><div><font face="courier new, monospace">Rich</font></div></div>