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.17.1 and Agent — Elixir v1.17.1, 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

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
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
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement