josefrichter

josefrichter

TLDR: what’s the difference between Task.Supervisor.async_nolink and Taks.start, and which one I should call in Phoenix controllers, please?

Full story:

I have read several threads here and several blogposts on using simple Tasks, and would like to solidify my understanding

I understand you shouldn’t use Task.async if you don’t need to Task.await.

In those situations, it seems like I should use either Task.Supervisor.async_nolink which has the benefit that it’s not linked to process that started it (in my case e.g. the phoenix controller process that dies too soon and would take down this task with it), but you are still able to supervise it and handle failures if I got that right. (For which you’d need a GenServer to handle that?).

Another option seems to be Task.start which docs say only used when the task is used for side-effects (i.e. no interest in the returned result) - so is this one the truly simplest fire & forget? Not linked with anything, no idea whether it succeeds or not, not particularly important?

Example of my specific use case: I have a simple todo list, and when users check any of the todos, I want to run a background check whether all his todos are finished and send an email if yes - all of this can happen in the background without the user knowing, maybe only me as admin should see the failure somewhere in logs.

Just a note: I am not looking for a library, which probably exists. I’d like a pure elixir solution in order to learn and understand first.

Thank you!

Marked As Solved

wojtekmach

wojtekmach

Hex Core Team

Ah, yup! If you don’t intend to await you shouldnt async_nolink either, start_child is the way to go.

Also Liked

wojtekmach

wojtekmach

Hex Core Team

You’re right that both Task.Supervisor.async_nolink and Task.start are not linked to the current process, that’s often what we want. The difference is the former is linked to the task supervisor. This means when the application goes down, your task will be properly cleaned up too. In the case of Task.start because it’s not linked to anything, it may be left dangling.

wolf4earth

wolf4earth

This response to a different but similar thread might answer your question:

harmon25

harmon25

I usually create a named task supervisor in the applications supervision tree. This makes it easier to leverage observer to keep an eye on their execution.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews