应用开始在灵药
问题描述:
从文档:应用开始在灵药
def application do
[mod: {MyApp, []}]
end
很多时候,应用程序定义了必须 启动和停止时,应用程序启动和停止监督树。为此,我们需要定义一个应用程序模块回调函数 。第一步是 定义应用程序定义的模块回调在 mix.exs文件:
但是,从文档存在,目前尚不清楚,什么是MyApp的后的名单(第二个参数)。
它应该是我的模块的列表实现GenServer
行为?
答
元组中的第二个值是作为第二个参数传递给MyApp.start/2
的参数。
如果你作出这样的:
def application do
[mod: {MyApp, [:foo, :bar]}]
end
,然后在MyApp.start
,检查第二个参数(由默认mix
发电机名为args
):
def start(_type, args) do
IO.inspect args
...
end
,然后运行mix
,你会参见:
$ mix
[:foo, :bar]