【发布时间】:2018-03-22 05:41:26
【问题描述】:
我对长生不老药/凤凰很陌生。我正在开发一个以前创建的具有多个存储库的应用程序,今天我看到一个示例,让我想知道该配置意味着什么
我想我不知道如何搜索这就是我在文档中找不到正确答案的原因
首先我正在使用的应用程序有类似
defmodule RestApi do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
supervisor(RestApi.Endpoint, []),
supervisor(RestApi.Repo, []),]),
supervisor(RestApi.OtherRepo, []),]),
]
opts = [strategy: :one_for_one, name: RestApi.Supervisor]
Supervisor.start_link(children, opts)
end
def config_change(changed, _new, removed) do
RestApi.Endpoint.config_change(changed, removed)
:ok
end
end
他们使用函数Supervisor.Spec.supervisor/3 来启动/管理一切
后来我找到了一个例子
defmodule RestApi do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
supervisor(RestApi.Endpoint, []),
worker(RestApi.Repo, []),
]
opts = [strategy: :one_for_one, name: RestApi.Supervisor]
Supervisor.start_link(children, opts)
end
def config_change(changed, _new, removed) do
RestApi.Endpoint.config_change(changed, removed)
:ok
end
end
在example 中,他们使用Supervisor.Spec.worker/3 来启动/管理回购
这有什么区别?我的意思是如何影响应用程序(性能、内存消耗等)
【问题讨论】:
-
请注意,elixir 1.5 最近发生了一些变化,看起来更简单了。查看更新日志github.com/elixir-lang/elixir/blob/v1.5/CHANGELOG.md 和
Supervisor文档hexdocs.pm/elixir/Supervisor.html。