Aaron Feng on 22 Oct 2007 14:09:12 -0000 |
I posted the following question last night on Erlang's mailing list. No one seems to know the answer to this question so far. Maybe someone here would know. The following code snippet appeared on page 352: -module(sellaprime_supervisor). -behaviour(supervisor). -export([start/0, start_in_shell_for_testing/0, start_link/1, init/1]). start() -> spawn(fun() -> supervisor:start_link({local, ?MODULE}, ?MODULE, _Arg = []) end). start_in_shell_for_testing() -> {ok, Pid} = supervisor:start_link({local,?MODULE}, ?MODULE, _Arg = []), unlink(Pid). %% rest of the code intentionally left out What's the benefit of calling spawn on supervisor:start_link in the start() function? Why not just call supervisor:start_link without the spawn? Doesn't supervisor:start_link already spawn and register the process already? In fact, if you use spawn on supervisor:start_link you can't get to the process the supervisor manages, at least I don't know how. For example, the supervisor manages two worker processes: area_server and prime_server. In the shell, the supervisor is started using the start() with the spawn in it. I'm unable to call the area_server's function using its registered process name. If I remove the spawn from the start(), I can call area_server's function in the shell. Also to notice, the function used to test the supervisor in the shell (start_in_shell_for_testing()) doesn't have the spawn in it. Thanks in advance, Aaron --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Philly Lambda" group. To unsubscribe from this group, send email to philly-lambda-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/philly-lambda?hl=en -~----------~----~----~----~------~----~------~--~---
|
|