vrod

vrod

I have another question about concurrency in Elixir I hope someone can help me understand. I have been studying the Task module. I am reading the documentation for the Task.async_stream/5 Task — Elixir v1.20.2
but I am confused by the ordered option. I think I understand what it does – if it is false then tasks a, b, and c may be returned in some different order like b, c, a.

However, I am struggling to understand these sentences: “This option is useful when you have large streams and don’t want to buffer results before they are delivered. This is also useful when you’re using the tasks for side effects.”

Is that saying that using ordered: false is useful when you have large streams? And should I use ordered: false if I am only using the task for side effects?

I think that makes sense, but I do not trust my own understanding with this yet.

Thank you for clarifying!

Showing Posts 1 to 5

gregvaughn

gregvaughn

I don’t know why they mention side effects in the docs. Seems to me those could be sensitive to ordering. It really all depends on your algorithm whether the order of the results is important to preserve.

If you have ordered: true but the tasks complete in order of b, a, c, then the internal logic has to buffer the result of b, wait for a to finish, send a’s result downstream, then it sends the buffered b’s response, etc.

If your algorithm can operate correctly with ordered: false I would recommend it, no matter the size of the stream or side-effects.

John-Goff

John-Goff

I think it could be better worded as “when you’re using tasks only for the side effects”. The ordered key will not make side effects occur in the order of the enumerable, it’ll only affect the returned stream. Side effects will always occur when the task is processed, so if you need to rely on side effect order you should use Enum.each or Enum.map. As you point out, with ordered: false, there’s no need to buffer the results. So the docs are saying basically if you’re going to pipe Task.async_stream into Enum.each, you should use ordered: false.

josevalim

josevalim

Creator of Elixir

Both of your points are great, PR to the docs are appreciated. :slight_smile:

John-Goff

John-Goff

I’ve never had the chance to submit a pr to the docs, this seems like a great opportunity! I’ll get on that today :smile:

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews