Reputation: 1392
Trying to terminate a child by its pid does not work, it should according to the documentation : https://hexdocs.pm/elixir/1.3.3/Supervisor.html#terminate_child/2
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}
Any clues to make it work ?
Upvotes: 0
Views: 364
Reputation: 222398
You need to pass the child id to terminate_child
for all strategies except :simple_one_for_one
. So, for :one_for_one
, the following should work for you since the id
is set to the module by Supervisor.Spec.worker/3
if one is not provided:
Supervisor.terminate_child(sup, RData.ExpectedRefurbishmentCost)
Upvotes: 3