Question: parallel async CE
First, many thanks for the update.
I wondered what your thoughts are on a parallelAsyncCE? There exist parallelResultCE and parallelValidationCE, but no parallelAsyncCE. Is it because there is no asyncCE because that is included in the F# Core libraries, or are there other reasons?
Happy coding, Urs
I think this would be a good addition since and! for the official async CE was rejected.
There might be overlap with IcedTasks, however: https://github.com/TheAngryByrd/IcedTasks/blob/7c9ab05fc64e4f2dca99d130eae91a0243516cf8/src/IcedTasks/ParallelAsync.fs#L130-L133
Note that there are several different ways to "zip" two asyncs. This library uses Async.Parallel, which is different to IcedTasks.
The different implementation possibilities are the reason why I'm not confident in implementing this correctly on my own. I don't know the implications of the different approaches.
You can use the Async.parallelMap2 implementation from this library with regular async:
#r "nuget: FsToolkit.ErrorHandling, 5"
open FsToolkit.ErrorHandling
let foo =
async {
return 1
}
let bar =
async {
return 2
}
async {
let! x, y = Async.parallelMap2 (fun x y -> x, y) foo bar
return x + y
}
Or with CE syntax:
#r "nuget: FsToolkit.ErrorHandling, 5"
open FsToolkit.ErrorHandling
type AsyncBuilder with
member this.MergeSources(x, y) =
Async.parallelMap2 (fun i j -> i, j) x y
let foo =
async {
return 1
}
let bar =
async {
return 2
}
async {
let! x = foo
and! y = bar
return x + y
}
Yeah, IcedTasks has an parallelAsync implementation, however it doesn't support Fable like FsToolkit does. I'll have to think about if it makes sense to put it here because of that.
njlr's solution would work if you need it for Fable or you can used IcedTask's implementation.
We use the implementation of IcedTask in our own extension to the normal AsyncBuilder. I guess it would be nice to have a parallelAsync in FsToolkit, though.