问题描述
执行 inets的适当位置是:start()
?
- 在applicationname_app模块中
- 在
applicationname_sup
主管模块中 - 过程挂在主管身上?\
- 别的地方?
- in `applicationname_app' module?
- in
applicationname_sup
supervisor module? - in a child process hanging from the supervisor?\
- someplace else?
(我还在挣扎与 inets:httpd
)
注意:答案无法调整使用引导文件。
Note: the answer cannot be to the tune " use a boot file " , please.
推荐答案
inets是一个独立Erlang应用程序; inets:start()
只是应用程序的别名:start(inets)
。我想这个答案在很大程度上取决于你如何维护你的代码。
inets is a "stand-alone" Erlang application; inets:start()
is just an alias to application:start(inets)
. I guess the answer pretty much depends on how you maintain your code.
如果你的代码打包成一个,您的.app文件应根据需要列出 inets
在你的之前启动(见应用程序标签)。开始使用应用程序的应用程序:start(my_app)。
现在将确保inets也启动。结果:如果您创建一个引导文件,它也将为您启动in-in:-P
If your code is packaged as an application, your .app file should list inets
as required to be started before yours (see the applications tag). Starting your applicaion with application:start(my_app).
will now ensure that inets is also started. Consequence: if you make a boot file, it will also start inets for you :-P
如果您热衷于不使用应用程序,我猜想选择取决于你的代码工作。如果您始终需要入门入门,最好由任何主管开始。如果很少需要,您可以随时确定它是由以下开始:
If you are keen on not using applications, I guess the choice depends on how your code works. If you will always need inets to be started, it is better started by any of your supervisors. If it is rarely needed, you can always make sure it is started with something like:
ensure_app_started(App) ->
case application:started(App) of
ok -> ok;
{error, already_started} -> ok;
Error -> Error
end.
这篇关于Erlang:何时执行`inets:start()`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!