我寫了一個名爲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