Current section
Files
Jump to
Current section
Files
src/evel_agent_sup.erl
%% Copyright (c) 2016 Takeru Ohta <phjgt308@gmail.com>
%%
%% This software is released under the MIT License.
%% See the LICENSE file in the project root for full license information.
%%
%% @doc The Supervisor for even_agent processes
%% @private
%% @end
-module(evel_agent_sup).
-behaviour(supervisor).
%%----------------------------------------------------------------------------------------------------------------------
%% Exported API
%%----------------------------------------------------------------------------------------------------------------------
-export([start_link/0]).
-export([start_child/1]).
-export([which_children/0]).
%%----------------------------------------------------------------------------------------------------------------------
%% 'supervisor' Callback API
%%----------------------------------------------------------------------------------------------------------------------
-export([init/1]).
%%----------------------------------------------------------------------------------------------------------------------
%% Exported Functions
%%----------------------------------------------------------------------------------------------------------------------
%% @doc Starts the supervisor
-spec start_link() -> {ok, pid()} | {error, Reason::term()}.
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
%% @doc Starts a child
-spec start_child(evel_agent:start_arg()) -> {ok, pid()} | {error, Reason::term()}.
start_child(Arg) ->
supervisor:start_child(?MODULE, [Arg]).
%% @doc Returns a list of running children
-spec which_children() -> [evel_agent:agent()].
which_children() ->
[Pid || {_, Pid, _, _} <- supervisor:which_children(?MODULE), is_pid(Pid)].
%%----------------------------------------------------------------------------------------------------------------------
%% 'supervisor' Callback Functions
%%----------------------------------------------------------------------------------------------------------------------
%% @private
init([]) ->
Child = #{id => token, start => {evel_agent, start_link, []}, restart => temporary},
{ok, {#{strategy => simple_one_for_one}, [Child]}}.