简体   繁体   English

Erlang如何将参数从模块传递到另一个

[英]Erlang how to pass parameter from module to another

I have an application written in erlang, i added a supervisor for distribution and now after parsing the configFile.cfg in the supervisor, i want to pass the configuration to my old application. 我有一个用erlang编写的应用程序,我添加了一个管理器以进行分发,现在在管理器中解析configFile.cfg之后,我想将配置传递给我的旧应用程序。 i have something like this now: 我现在有这样的事情:

-module(supervisor_sup).
start() ->
    application_app:start().

what i want is: 我想要的是:

-module(supervisor_sup).

-record(config,{param1,param2}).
%After parsing the configFile.cfg
Conf = #config{param1 = Param1,
            param2 = Param2},

start(Conf) ->
    application_app:start(Conf).

It is uncommon to start applications from supervisors or modules under supervisors. 从主管或主管下的模块启动应用程序并不常见。 The preferred way is to use application dependency to make sure all applications are started, and in the right order. 首选方法是使用应用程序依赖关系,以确保所有应用程序均已按正确的顺序启动。

However, if you want some configuration to be available from several different applications without having to parse the configuration more than once, maybe the gproc library is what you are looking for? 但是,如果您希望可以从多个不同的应用程序中获得某些配置,而不必多次解析该配置,那么gproc库正是您要找的东西吗? https://github.com/uwiger/gproc https://github.com/uwiger/gproc

gproc can be used to efficiently set global configuration and much more. gproc可用于有效设置全局配置等等。 Even in a distributed environment. 即使在分布式环境中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM