【问题标题】:Erlang supervisor:start_child parametersErlang supervisor:start_child 参数
【发布时间】:2013-02-09 00:14:17
【问题描述】:

我试图从 ErlNNTP 中理解这段主管代码,即使在阅读了关于 start-child (http://www.erlang.org/doc/man/supervisor.html#start_child-2) 的 erlang 文档 (Erlang n00b) 之后,我也无法理解它

start_connection_handler (Socket) -> supervisor:start_child (?MODULE, {Socket, {connection_handler, start_link, [Socket]}, 永久, 10000, worker, [connection_handler]})。

我不太了解我希望成为 SupRef 的“Socket”参数。我显然没有正确解析参数列表或理解调用。谁能给我解释一下?

【问题讨论】:

    标签: erlang nntp


    【解决方案1】:

    supervisor:start_child/2 的第二个参数是一个子规范,格式为:

    {Id,StartFunction,RestartType,Shutdowntime,ProcessType,Modules}
    

    在哪里

    • Id是在supervisor中唯一的child的标识符,可以是任何数据类型。

    • StartFunction 是一个元组{Module,Function,Args},它是启动子进程的调用。

    • RestartType 告诉主管如何重新启动这个孩子,它的值可以是permanenttransienttemporary

    • ShutdownTime 是允许子进程在终止前花费多少。

    • ProcessType 孩子是worker 还是supervisor

    • Modules 实现子模块的列表

    代码升级时使用后两个。

    因此,在您的情况下,Socket 被用作标识符。这样做意味着当您为新套接字启动处理程序时,您将获得一个唯一标识符。

    【讨论】:

    • 优秀。这就解释了。谢谢
    猜你喜欢
    • 2013-06-01
    • 2013-04-06
    • 2011-06-27
    • 2017-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多