fireproofsocks

fireproofsocks

Task.start/1 vs. Task.start/3

Just wanting to make sure… there are a handful of functions in the Task module that support different arities, e.g. Task.start/1 vs. Task.start/3, or Task.async_stream/3 vs. Task.async_stream/5. In all cases, the difference boils down to either passing an anonymous function (defined with fn) or using the long-form MFA notation.

From reading a bit about Task — Elixir v1.20.2 and Agent — Elixir v1.20.2, I understand that sometimes you MUST use the more verbose MFA notation to properly designate a function that will execute. Is the MFA notation only required when we are dealing with distributed nodes? Are the shorter function signatures (e.g. Task.start/1) only a convenience, or are there any cases where you would want to require that all instances of the module + function were the same version?

Most Liked

al2o3cr

al2o3cr

Mostly it’s a matter of “those are the two ways in the BEAM to identify code that should be turned into a process”; see also the core spawn/1,2,3,4 function.

There are situations where an anonymous function isn’t allowed (for instance, in config) and there are other situations where an MFA can’t name the desired function (for instance, private functions) so both forms are useful.

gregvaughn

gregvaughn

Anonymous functions can also cause problems during live module upgrades, a.k.a. hot deploys.

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement