Task.Supervisor: start_child vs async_nolink

819 views
Skip to first unread message

Po Chen

unread,
May 4, 2016, 11:29:53 PM5/4/16
to elixir-lang-talk
Hi all,

so Task.Supervisor has start_child and async_nolink, both of them DON'T link to the caller, when should you use which?

@benwilson512 kindly replied to me on Slack:

benwilson512 11:07 AM
If you plan on awaiting or yielding
Use async no link.
If you want a fire and forget
Use start child

However, I have some more questions:

Does one cover the functionality of the other?
If you want a fire and forget, you could still use async no link though, couldn't you?
Is there any scenario that you should absolutely use start_child instead of async_nolink?


Thanks,
Po

Ben Wilson

unread,
May 4, 2016, 11:56:23 PM5/4/16
to elixir-lang-talk
The code itself provides the main differences.


async_nolink on the other hand spawns the process under a supervisor, monitors it, and sends it a message.

My previous point still stands though, because while an extra monitor and a couple of extra messages sent aren't a big deal, the larger point is semantic. start_child makes it clear that you don't care about the result. async_nolink implies that you probably do, or at a minimum care about the life of task as the monitor will tell you when when it dies.

Po Chen

unread,
May 5, 2016, 12:10:16 AM5/5/16
to elixir-lang-talk
Hi Ben,

Thank you very much for the detailed answer :) that helps a lot.
Reply all
Reply to author
Forward
0 new messages