这是application master的部分源代码,它是管理 erlang 应用程序的模块。
348 loop_it(Parent, Child, Mod, AppState) ->
349 receive
350 {Parent, get_child} ->
351 Parent ! {self(), Child, Mod},
352 loop_it(Parent, Child, Mod, AppState);
353 {Parent, terminate} ->
354 NewAppState = prep_stop(Mod, AppState),
355 exit(Child, shutdown),
356 receive
357 {'EXIT', Child, _} -> ok
358 end,
359 catch Mod:stop(NewAppState),
360 exit(normal);
361 {'EXIT', Parent, Reason} ->
362 NewAppState = prep_stop(Mod, AppState),
363 exit(Child, Reason),
364 receive
365 {'EXIT', Child, Reason2} ->
366 exit(Reason2)
367 end,
368 catch Mod:stop(NewAppState);
369 {'EXIT', Child, Reason} -> % forward *all* exit reasons (inc. normal)
370 NewAppState = prep_stop(Mod, AppState),
371 catch Mod:stop(NewAppState),
372 exit(Reason);
373 _ ->
374 loop_it(Parent, Child, Mod, AppState)
375 end.
我的问题是:
为什么 application master 在收到 {Parent, terminate} 和 {'EXIT', Parent, Reason} 时的行为不同?
第 368 行的代码是什么意思?应用程序主机必须在第 366 行之前退出。