Replies: 6 comments
-
With Aff<(R1, R2)> mx = (Request1(), Request2()).Sequence(); With up to 5 items in the tuple (which will all run in parallel, and only return when all are complete).
|
Beta Was this translation helpful? Give feedback.
-
@louthy Thank you for answering the question, that's really great that way. So this works more or less like Task.WhenAll(), but then it leads to another question: Is there also an equivalent to Task.WhenAny()? |
Beta Was this translation helpful? Give feedback.
-
@louthy Okay, I have even more questions now, for example how to work with a list of Aff<>.
I guess with Aff, when both GetProducts and GetPicture are returning it, it would look something like this:
In this case they probably wouldn't run in parallel and additionally nesting is starting to get a bit complicated to resolve. I guess there will also be a better and easier way, beside of wrapping the operation into a function which pretends to handle the whole bulk |
Beta Was this translation helpful? Give feedback.
-
This is what In general when you see |
Beta Was this translation helpful? Give feedback.
-
What more important IMHO is e.g. if you have an Enumerable<Task<Sideeffects (external API-Call)>>. (It´s like groupBy(count) and foldLeft in scala, if you don´t want to use fs2 or akka.streams). Btw. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your answers, no questions then anymore. Sorry that I seem to have overlooked it. And I can agree, it's really a great library! |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have a little question about the best way handling two different async Monads with side effects, like Aff and TryAsync.
The best thing about async is that it frees the thread for work while an asynchronous operation is waiting for a result of an external source. So sometimes, when two tasks are indepentend of each other, it allows us to run them kind of parallel. In the example below we have to start two different http requests which do not need the result of the other, so we can start the second before the first one has finished
But things get tricky (for me) when it comes to the effect monads. In the following example I will return Aff instead of raw Tasks, but the only way I found to run the execution like the one above is with calling Run on both and awaiting the Fin.
However, from my understanding of the docs the effects should be composed and only be run once at the start of the application, which is broken by this code style.
I understand that this code is not executed directly when wrapped in another Aff itself. That way the rule can be followed but I don't know if that's how it's supposed to be.
So am I missing another way to achieve the effect of the code in the example above?
Beta Was this translation helpful? Give feedback.
All reactions