@@ -10,7 +10,7 @@ module Async =
10
10
let map f x = async.Bind ( x, async.Return << f)
11
11
12
12
/// <summary>Creates an async workflow from two workflows 'x' and 'y', mapping its results with 'f'.</summary>
13
- /// <remarks>Workflows are run in sequence.</remarks>
13
+ /// <remarks>Workflows are run in sequence, for parallel use pmap2 .</remarks>
14
14
/// <param name="f">The mapping function.</param>
15
15
/// <param name="x">First async workflow.</param>
16
16
/// <param name="y">Second async workflow.</param>
@@ -20,7 +20,7 @@ module Async =
20
20
return f a b}
21
21
22
22
/// <summary>Creates an async workflow from three workflows 'x', 'y' and 'z', mapping its results with 'f'.</summary>
23
- /// <remarks>Workflows are run in sequence.</remarks>
23
+ /// <remarks>Workflows are run in sequence, for parallel use pmap3 .</remarks>
24
24
/// <param name="f">The mapping function.</param>
25
25
/// <param name="x">First async workflow.</param>
26
26
/// <param name="y">Second async workflow.</param>
@@ -31,6 +31,43 @@ module Async =
31
31
let! c = z
32
32
return f a b c}
33
33
34
+ /// <summary>Creates an async workflow from two workflows 'x' and 'y', mapping its results with 'f'.</summary>
35
+ /// <remarks>Similar to map2 but workflows are run in parallel.</remarks>
36
+ /// <param name="f">The mapping function.</param>
37
+ /// <param name="x">First async workflow.</param>
38
+ /// <param name="y">Second async workflow.</param>
39
+ #if FABLE_ COMPILER
40
+ let pmap2 f x y = map2 f x y
41
+ #else
42
+ let pmap2 f x y = async {
43
+ let! ct = Async.CancellationToken
44
+ let x = Async.StartImmediateAsTask ( x, ct)
45
+ let y = Async.StartImmediateAsTask ( y, ct)
46
+ let! x ' = Async.AwaitTask x
47
+ let! y ' = Async.AwaitTask y
48
+ return f x' y' }
49
+ #endif
50
+
51
+ /// <summary>Creates an async workflow from three workflows 'x', 'y' and 'z', mapping its results with 'f'.</summary>
52
+ /// <remarks>Similar to map3 but workflows are run in parallel.</remarks>
53
+ /// <param name="f">The mapping function.</param>
54
+ /// <param name="x">First async workflow.</param>
55
+ /// <param name="y">Second async workflow.</param>
56
+ /// <param name="z">third async workflow.</param>
57
+ #if FABLE_ COMPILER
58
+ let pmap3 f x y z = map3 f x y z
59
+ #else
60
+ let pmap3 f x y z = async {
61
+ let! ct = Async.CancellationToken
62
+ let x = Async.StartImmediateAsTask ( x, ct)
63
+ let y = Async.StartImmediateAsTask ( y, ct)
64
+ let z = Async.StartImmediateAsTask ( z, ct)
65
+ let! x ' = Async.AwaitTask x
66
+ let! y ' = Async.AwaitTask y
67
+ let! z ' = Async.AwaitTask z
68
+ return f x' y' z' }
69
+ #endif
70
+
34
71
/// <summary>Creates an async workflow from two workflows 'x' and 'y', tupling its results.</summary>
35
72
let zip x y = async {
36
73
let! a = x
0 commit comments