这是正确的儿童规格吗?

时间:2012-04-11 10:17:50

标签: erlang

我注意到牛仔https://github.com/extend/cowboy

中的代码如下
supervisor:start_child(cowboy_sup, child_spec(Ref, NbAcceptors,
    Transport, TransOpts, Protocol, ProtoOpts)).

child_spec(Ref, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts) ->  
{{cowboy_listener_sup, Ref}, {cowboy_listener_sup, start_link, [ NbAcceptors, Transport,
TransOpts, Protocol, ProtoOpts ]}, permanent, 5000, supervisor,[cowboy_listener_sup]}.

http://www.erlang.org/doc/man/supervisor.html#start_child-2

我不认为这是正确的孩子规格,你怎么看待它?

1 个答案:

答案 0 :(得分:3)

您可以使用supervisor:check_childspecs/1功能验证子规格的正确性。

是的,这看起来像一个有效的儿童规范:

child_spec() = 
    {Id :: child_id(),
     StartFunc :: mfargs(),
     Restart :: restart(),
     Shutdown :: shutdown(),
     Type :: worker(),
     Modules :: modules()}

其中:

Id -> {cowboy_listener_sup, Ref}
StartFunc -> {cowboy_listener_sup, start_link, [ ... ]}
Restart -> permanent
Shutdown -> 5000
Type -> supervisor
Modules -> [cowboy_listener_sup]

究竟是什么疑问?