2017-02-10 58 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)