View Source partisan_gen_supervisor behaviour (partisan v5.0.0-beta.21)
This module is an adaptation of Erlang's supervisor
module.
supervisor
is when you need to supervise remote processes i.e. if you just need to supervise local partisan_gen_server
or partisan_gen_statem
processes you can still use OTP's supervisor
. It replaces all the usage of modules gen_server
and functions erlang:is_pid/0
and erlang:monitor/2
with their Partisan counterparts.
Link to this section Summary
Types
XXX: refine
Link to this section Types
-type auto_shutdown() :: never | any_significant | all_significant.
-type call() :: which_children | count_children | {_, _}.
-type child() :: undefined | pid2().
-type child_id() :: term().
-type child_rec() :: #child{}.
-type child_spec() :: #{id := child_id(), start := mfargs(), restart => restart(), significant => significant(), shutdown => shutdown(), type => worker(), modules => modules()} | {Id :: child_id(), StartFunc :: mfargs(), Restart :: restart(), Shutdown :: shutdown(), Type :: worker(), Modules :: modules()}.
-type init_sup_name() :: sup_name() | self.
-type mfargs() :: {M :: module(), F :: atom(), A :: [term()] | undefined}.
-type modules() :: [module()] | dynamic.
-type pid2() :: pid() | partisan_remote_ref:p().
-type restart() :: permanent | transient | temporary.
-type shutdown() :: brutal_kill | timeout().
-type significant() :: boolean().
-type startchild_err() :: already_present | {already_started, Child :: child()} | term().
-type startchild_ret() :: {ok, Child :: child()} | {ok, Child :: child(), Info :: term()} | {error, startchild_err()}.
-type startlink_err() :: {already_started, pid2()} | {shutdown, term()} | term().
-type startlink_ret() :: {ok, pid2()} | ignore | {error, startlink_err()}.
-type state() :: #state{}.
-type stop_rsn() ::
{shutdown, term()} |
{bad_return, {module(), init, term()}} |
{bad_start_spec, term()} |
{start_spec, term()} |
{supervisor_data, term()}.
-type strategy() :: one_for_all | one_for_one | rest_for_one | simple_one_for_one.
-type sup_flags() :: #{strategy => strategy(), intensity => non_neg_integer(), period => pos_integer(), auto_shutdown => auto_shutdown()} | {RestartStrategy :: strategy(), Intensity :: non_neg_integer(), Period :: pos_integer()}.
-type sup_name() ::
{local, Name :: atom()} | {global, Name :: term()} | {via, Module :: module(), Name :: any()}.
-type sup_ref() :: (Name :: atom()) | {Name :: atom(), Node :: node()} | {global, Name :: term()} | {via, Module :: module(), Name :: any()} | pid2().
-type worker() :: worker | supervisor.
Link to this section Callbacks
-callback init(Args :: term()) -> {ok, {SupFlags :: sup_flags(), [ChildSpec :: child_spec()]}} | ignore.
Link to this section Functions
-spec check_childspecs(ChildSpecs) -> Result when ChildSpecs :: [child_spec()], Result :: ok | {error, Error :: term()}.
-spec check_childspecs(ChildSpecs, AutoShutdown) -> Result when ChildSpecs :: [child_spec()], AutoShutdown :: undefined | auto_shutdown(), Result :: ok | {error, Error :: term()}.
-spec count_children(SupRef) -> PropListOfCounts when SupRef :: sup_ref(), PropListOfCounts :: [Count], Count :: {specs, ChildSpecCount :: non_neg_integer()} | {active, ActiveProcessCount :: non_neg_integer()} | {supervisors, ChildSupervisorCount :: non_neg_integer()} | {workers, ChildWorkerCount :: non_neg_integer()}.
-spec get_callback_module(Pid) -> Module when Pid :: pid(), Module :: atom().
-spec get_childspec(SupRef, Id) -> Result when SupRef :: sup_ref(), Id :: pid2() | child_id(), Result :: {ok, child_spec()} | {error, Error}, Error :: not_found.
-spec init({init_sup_name(), module(), [term()]}) -> {ok, state()} | ignore | {stop, stop_rsn()}.
-spec start_child(SupRef, ChildSpec) -> startchild_ret() when SupRef :: sup_ref(), ChildSpec :: child_spec() | (List :: [term()]).
-spec start_link(Module, Args) -> startlink_ret() when Module :: module(), Args :: term().
-spec start_link(SupName, Module, Args) -> startlink_ret() when SupName :: sup_name(), Module :: module(), Args :: term().
-spec terminate(term(), state()) -> ok.