Erlang:何时执行`inets:start()`?
执行 inets:start() 的适当位置是什么?
- 在“applicationname_app”模块中?
- 在
applicationname_sup
管理模块中? - 在从主管挂起的子进程中?\
- 在其他地方?
(我仍在与 inets:httpd
作斗争)
注意:答案不能是“使用启动文件”。
What is the appropriate place for performing inets:start()
?
- in `applicationname_app' module?
- in
applicationname_sup
supervisor module? - in a child process hanging from the supervisor?\
- someplace else?
(I am still struggling with inets:httpd
)
Note: the answer cannot be to the tune " use a boot file " , please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
inets 是一个“独立”的 Erlang 应用程序;
inets:start()
只是application:start(inets)
的别名。我想答案很大程度上取决于您如何维护代码。如果您的代码打包为 应用程序,您的 .app 文件应列出
inets
根据需要在您的之前启动(请参阅应用程序标签)。使用application:start(my_app).
启动应用程序现在将确保 inets 也启动。结果:如果您创建启动文件,它也会为您启动 inets :-P如果您热衷于不使用应用程序,我想选择取决于您的代码如何工作。如果您总是需要启动 inets,那么最好由您的任何主管启动。如果很少需要它,您始终可以确保它以如下方式启动:
inets is a "stand-alone" Erlang application;
inets:start()
is just an alias toapplication:start(inets)
. I guess the answer pretty much depends on how you maintain your code.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 withapplication: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 :-PIf 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:
2019 年,我们使用
rebar3
来创建应用程序并管理其依赖项。对于需要下载的依赖项,将其添加到rebar.config
中,rebar3
将下载依赖项。例如,如果您将hackney
(http 客户端)添加到 rebar.config:然后执行:
rebar3
将下载hackney
并编译所有文件在应用程序
中。为了确保所有依赖项在应用程序之前启动,请将依赖项的名称添加到:
例如,
实际的 .app 文件在此处创建:
要在 shell 中启动应用程序及其所有依赖项,您需要执行以下操作:
inets
应用程序随 erlang 一起提供,因此无需下载,因此您无需在 rebar.config 中指定 inets 作为依赖项(当您$ rebar3 编译
)。您仍然需要在文件中的application
中指定 inets 作为依赖项:但是
rebar3
本身使用inets
(下载您的依赖项),因此即使您没有在应用程序中将inets
指定为依赖项,inets
仍会在您的应用之前启动。您可以通过不在应用程序中指定inets
作为依赖项来测试这一点,然后执行以下操作:但是,不要依赖它并指定
inets
> 作为应用程序中的依赖项。In 2019, we use
rebar3
to create an application and manage its dependencies. For dependencies that need to be downloaded, you add them torebar.config
, andrebar3
will download the dependencies. For example, if you addhackney
(an http client) to rebar.config:Then do:
rebar3
will downloadhackney
and compile all the files in theapplication
.To make sure that all your dependencies get started before your app, you add the names of the dependencies to:
For instance,
The actual .app file gets created here:
To start your app in the shell along with all its dependencies, you do:
The
inets
application comes with erlang, so it doesn't need to be downloaded, so you don't specify inets as a dependency in rebar.config (you'll get an error when you$ rebar3 compile
). You still need to specify inets as a dependency in yourapplication
in the file:But
rebar3
itself usesinets
(to download your dependencies), so even if you didn't specifyinets
as a dependency in your application,inets
would still get started before your app. You can test that by not specifyinginets
as a dependency in yourapplication
, then doing:But, don't rely on that and DO specify
inets
as a dependency in your application.如果您的代码打包为应用程序,请列出
inets
在应用程序资源文件中:然后您可以使用
启动应用程序应用程序:ensure_all_started(flamingo)
。这可确保 inets 自动为您启动(即无需显式调用inets:start()
)。例如(假设 *.app 文件和 *.beam 文件位于
ebin/
中):If your code is packaged as an application, list
inets
in the application resource file:Then you can start the application using
application:ensure_all_started(flamingo)
. This ensures that inets is started automatically for you (i.e. there is no need to explicitly callinets:start()
).For example (assuming the *.app file and *.beam files and are in
ebin/
):