I had assume that the difference between the two is that Task.start spawns a child process from process where its called while Task.Supervisor.start_child spawns the child process off a supervisor.
Running from iex -S mix
. I am expecting for this i will see the child process printout “exiting child process…”
defmodule Foo do
def foo do
Task.Supervisor.start_child(
MyApp.TaskSupervisor,
fn ->
Process.sleep(:timer.seconds(10))
IO.puts("exiting child process...")
end
)
IO.puts("exiting...")
end
end
And for this i am not expecting to see the output because when foo runs to completion, the child process gets killed with it.
defmodule Foo do
def foo do
Task.start(fn ->
Process.sleep(:timer.seconds(10))
IO.puts("exiting child process...")
end)
IO.puts("exiting...")
end
end
However i am seeing printout for both cases. What am i understanding wrong here?