Packages
launchdarkly_server_sdk
2.1.2
3.11.0
3.10.1
3.9.0
3.8.1
3.8.0
3.7.2
3.7.1
3.7.0
3.6.0
3.5.0
3.4.0
3.3.1
3.3.0
3.2.0
3.1.0
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.1.2
2.1.1
2.1.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.6.0
1.5.0
1.4.0
1.3.2
1.3.1
1.3.0
1.2.0
1.1.3
1.1.2
1.1.1
retired
1.1.0
retired
1.0.1
retired
1.0.0
retired
1.0.0-beta4
retired
1.0.0-beta3
retired
1.0.0-beta2
retired
LaunchDarkly SDK for Erlang
Current section
Files
Jump to
Current section
Files
src/ldclient_updater.erl
%%-------------------------------------------------------------------
%% @doc `ldclient_updater' module
%% @private
%% Used to start and stop client stream listener.
%% @end
%%-------------------------------------------------------------------
-module(ldclient_updater).
%% API
-export([start/3]).
-export([stop/1]).
%% Constants
-define(CHILD(Id, Module, Args, Type), {Id, {Module, start_link, Args}, permanent, 5000, Type, [Module]}).
%%===================================================================
%% API
%%===================================================================
%% @doc Start client stream listener
%%
%% @end
-spec start(UpdateSupName :: atom(), UpdateWorkerModule :: atom(), Tag :: atom()) ->
{ok, pid()}.
start(UpdateSupName, UpdateWorkerModule, Tag) when is_atom(UpdateSupName), is_atom(UpdateWorkerModule) ->
{ok, _Pid} = supervisor:start_child(UpdateSupName, [Tag]).
%% @doc Stop client stream listener
%%
%% @end
-spec stop(Tag :: atom()) -> ok.
stop(StreamSupName) when is_atom(StreamSupName) ->
ok = terminate_all_children(StreamSupName).
%%===================================================================
%% Internal functions
%%===================================================================
%% @doc Terminates all children of a given supervisor
%% @private
%%
%% @end
-spec terminate_all_children(Sup :: atom()) -> ok.
terminate_all_children(Sup) ->
Pids = [Pid || {_, Pid, worker, _} <- supervisor:which_children(Sup)],
terminate_all_children(Sup, Pids).
%% @doc Recursively terminates processes of given children Pids
%% @private
%%
%% @end
-spec terminate_all_children(Sup :: atom(), [pid()]) -> ok.
terminate_all_children(_Sup, []) ->
ok;
terminate_all_children(Sup, [Pid|Rest]) ->
ok = supervisor:terminate_child(Sup, Pid),
terminate_all_children(Sup, Rest).