问题是,在Supervisor中你试试这个:
children = [
{
DynamicSupervisor,
name: SomeName,
strategy: :one_for_one
},
{
DynamicSupervisor,
name: AnotherName,
strategy: :one_for_one
}
]
你最终收到了这个:
**(混合)无法启动应用程序:
PocAbilityProvider.start(:normal,[])返回错误:坏孩子 规范,多个子规范有id: DynamicSupervisor。如果使用地图作为子规格,请确保 :id键是唯一的。如果使用模块或{module,arg}作为孩子, 使用Supervisor.child_spec / 2更改:id,例如:
children = [Supervisor.child_spec({MyWorker,arg},id: :my_worker_1),Supervisor.child_spec({MyWorker,arg},id: :my_worker_2)]
我试图推出像
这样的东西children = [
{
DynamicSupervisor,
name: SomeName,
strategy: :one_for_one,
id: :unique_id
},
{
DynamicSupervisor,
name: AnotherName,
strategy: :one_for_one,
id: :even_more_unique_id
}
]
children = [
{
DynamicSupervisor,
[
[
name: SomeName,
strategy: :one_for_one
],
id: :unique_id
]
},
{
DynamicSupervisor,
[
[
name: AnotherName,
strategy: :one_for_one
],
id: :even_more_unique_id
]
}
]
但它仍然会返回相同的错误。是否可以在一个主管下启动两个DynamicSupervisors?
答案 0 :(得分:2)
DynamicSupervisor.child_spec/1
隐式将NULL
定义为模块名称:id
。为了解决这个问题,可以使用module-based supervisors两者,使用不同的模块(如果行为应该完全相同,则不会是DRY),或者使用明确的Supervisor.child_spec/2
作为:
DynamicSupervisor
此包装器将覆盖默认的children = [
Supervisor.child_spec(
{DynamicSupervisor, []},
id: :id1, name: :name1, strategy: :one_for_one),
Supervisor.child_spec(
{DynamicSupervisor, []},
id: :id2, name: :name2, strategy: :one_for_one)
]
。
答案 1 :(得分:0)
children = [
Supervisor.child_spec(
{DynamicSupervisor, name: SomeName, strategy: :one_for_one},
id: :dyn_sup_1),
Supervisor.child_spec(
{DynamicSupervisor, name: AnotherName, strategy: :one_for_one},
id: : dyn_sup_2)]
这是启动两个或多个DynamicSupervisors的正确顺序