2017-02-10 57 views
0

试图通过其PID终止一个孩子没有工作的孩子,就应该根据文档:https://hexdocs.pm/elixir/1.3.3/Supervisor.html#terminate_child/2主管:不能终止通过PID

iex(7)> {:ok, sup} = Supervisor.start_link([], strategy: :one_for_one)       
{:ok, #PID<0.383.0>} 
iex(8)> {:ok, pid} = Supervisor.start_child(sup, worker(RData.ExpectedRefurbishmentCost, [self()])) 
{:ok, #PID<0.385.0>} 
iex(9)> Supervisor.terminate_child(sup, pid)              
{:error, :not_found} 

任何线索,使其工作?

+5

文档说,你需要通过子ID的所有策略,除了'simple_one_for_one' 。 PID仅适用于'simple_one_for_one'。 – Dogbert

+0

我超越了...... THX的精度:) – knotito

回答

3

对于除:simple_one_for_one之外的所有策略,您需要将子ID传递给terminate_child。因此,对于:one_for_one,下面应该为你,因为id工作由Supervisor.Spec.worker/3设置模块如果没有提供一个:

Supervisor.terminate_child(sup, RData.ExpectedRefurbishmentCost)