Last active
June 19, 2016 07:34
-
-
Save soranoba/8cca877203a04291b111543b046b46c4 to your computer and use it in GitHub Desktop.
A -> B -> C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-behaviour(gen_server). | |
init(_) -> | |
{ok, #state{member = undefined}}. | |
handle_call(_, _, #state{member = undefined} = State) -> {noreply, State}. | |
handle_cast({sync, Pids}, State) -> {noreply, #state{member = Pids}}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-behaviour(supervisor). | |
start_link() -> | |
case supervisor:start_link(?MODULE, []) of | |
{ok, Pid} -> | |
Pids = [Pid || {_, Pid, _, _} <- supervisor:which_children(Pid)], | |
ok = lists:foreach(fun(P) -> gen_server:cast(P, {sync, Pids}) end, Pids), | |
{ok, Pid}; | |
Err -> Err | |
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-behaviour(gen_server). | |
init([SupPid]) -> | |
ok = gen_server:cast(self(), sync), | |
{ok, #state{sup = SupPid}}. | |
handle_cast(sync, #state{sup = SupPid} = State) -> | |
%% この時点で全員の子が取得できるはず.... initの処理が重いとまずそう | |
Pids = [Pid || {_, Pid, _, _} <- supervisor:which_children(SupPid)], | |
{noreply, State#state{pids = Pids}}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-behaviour(supervisor). | |
start_link() -> | |
supervisor:start_link(?MODULE, []). | |
init(_) -> | |
SupPid = self(), | |
%% mfa以外は省略 | |
{ok, {{one_for_all, 5, 10}, [#{start => {M, F, [SupPid]}}, #{start => {M, F, [SupPid]}}, ...]}}. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aaaはtemporaryじゃないと使えない