Skip to content

Commit 891512d

Browse files
committed
Add book for parallelAsyncValidation
1 parent 101df35 commit 891512d

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

gitbook/parallelAsyncResult/ce.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Namespace: `FsToolkit.ErrorHandling`
44

55
This CE operates on the same type as `asyncResult`, but it adds the `and!` operator for running workflows in parallel.
66

7-
Concurrent workflows are run with the same semantics as [`Async.Parallel`](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-control-fsharpasync.html#Parallel), so only the first exception is returned.
7+
When running concurrent workflows, fail-fast semantics are used. If any sub-task returns an `Error`, then all other tasks are cancelled and only that error is returned. To instead collect all errors, use `parallelAsyncValidation`.
88

99

1010
## Examples
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## ParallelAsyncValidation Computation Expression
2+
3+
Namespace: `FsToolkit.ErrorHandling`
4+
5+
This CE operates in the same way as `asyncValidation`, except that the `and!` operator will run workflows in parallel.
6+
7+
Concurrent workflows are run with the same semantics as [`Async.Parallel`](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-control-fsharpasync.html#Parallel).
8+
9+
10+
## Examples
11+
12+
See [here](../validation/ce.md) for other validation-like examples
13+
14+
```fsharp
15+
// Result<string, string> -> Async<Result<string, string>>
16+
let downloadAsync stuff = async {
17+
return stuff
18+
}
19+
20+
// AsyncValidation<string, string>
21+
let addResult = parallelAsyncValidation {
22+
let! x = downloadAsync (Ok "I")
23+
and! y = downloadAsync (Ok "am")
24+
and! z = downloadAsync (Ok "concurrent!")
25+
return sprintf "%s %s %s" x y z
26+
}
27+
// async { return Ok "I am concurrent!" }
28+
29+
// AsyncValidation<string, string>
30+
let addResult = parallelAsyncValidation {
31+
let! x = downloadAsync (Error "Am")
32+
and! y = downloadAsync (Error "I")
33+
and! z = downloadAsync (Error "concurrent?")
34+
return sprintf "%s %s %s" x y z
35+
}
36+
// async { return Error [ "Am"; "I"; "concurrent?" ] }
37+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## ParallelAsyncValidation.map2
2+
3+
Namespace: `FsToolkit.ErrorHandling`
4+
5+
Function Signature:
6+
7+
```fsharp
8+
('a -> 'b -> 'c)
9+
-> Async<Result<'a, 'd list>>
10+
-> Async<Result<'b, 'd list>>
11+
-> Async<Result<'c, 'd list>>
12+
```
13+
14+
Like [ParallelAsyncResult.map2](../parallelAsyncResult/map2.md), but collects the errors from both arguments.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## ParallelAsyncValidation.map3
2+
3+
Namespace: `FsToolkit.ErrorHandling`
4+
5+
Function Signature:
6+
7+
```
8+
('a -> 'b -> 'c -> 'd)
9+
-> Async<Result<'a, 'e list>>
10+
-> Async<Result<'b, 'e list>>
11+
-> Async<Result<'c, 'e list>>
12+
-> Async<Result<'d, 'e list>>
13+
```
14+
15+
Like [ParallelAsyncResult.map3](../parallelAsyncResult/map3.md), but collects the errors from all arguments.
16+

0 commit comments

Comments
 (0)