我写了一个名为director的新库。
这是一个主管图书馆。
它的一个特点就是给人一种乐趣元数2〜主任,主任会调用函数过程的每一个崩溃,第一个参数是崩溃的原因和第二被碰撞计数,例如:理解Erlang/Elixir的监督职责
-module(director_test).
-behaviour(director).
-export([start_link/0, init/1]).
start_link() ->
director:start_link(?MODULE, []).
init([]) ->
ChildSpec = #{id => foo,
start => {m, f, args},
plan => [fun my_plan/2],
count => infinity},
{ok, [ChildSpec]}.
my_plan(normal, Count) when Count rem 10 == 0 ->
%% If process crashed with reason normal after every 10 times
%%, director will restart it after spending 3000 milliseconds.
{restart, 3000};
my_plan(normal, _Count) ->
%% If process crashed with reason normal director will restart its
restart;
my_plan(killed, _Count) ->
%% If process was killed, Director will delete it from its children
delete;
my_plan(Reason, Count) ->
%% For other reasons, director will crash with reason {foo_crashed, Reason}
{stop, {foo_crashed, Reason}}.
我宣布我在斯莱克的图书馆,他们想知道以这种方式写新的主管! 有人说:“我倾向于不让主管处理退后”。
最后,他们没有告诉我干净的信息,我想我需要更多地了解监管方和责任等 我认为主管是应该明白何时重启删除哪个孩子,当一个过程,孩子何时不重新启动哪个孩子。 对吗?
你能告诉我OTP /主管的一些很好的功能,我在导演有没有关系? (List of director's features)
通常当有新事物出现时,你的责任是展示你的库中有什么好处,以便我们依赖它而不是使用来自OTP核心的普通旧模式坐在那里从无到有? – mudasobwa
我做到了这一点(我认为),但问题是,他们导致我认为这是正确的方法,对吗? – Pouriya