Skip to content

Commit 6cae8d4

Browse files
committed
Add Task.WhenAllUnits
1 parent ba9ef7d commit 6cae8d4

File tree

1 file changed

+8
-3
lines changed
  • src/FSharpx.Extras/ComputationExpressions

1 file changed

+8
-3
lines changed

src/FSharpx.Extras/ComputationExpressions/Monad.fs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,10 +1183,16 @@ module Task =
11831183
)
11841184
)
11851185

1186+
/// Creates a single Task<unit> that will complete when all of the Task<unit> objects in an enumerable collection have completed.
1187+
let inline WhenAllUnits (units:seq<Task<unit>>) : Task<unit> =
1188+
task {
1189+
let! (_:unit[]) = Task.WhenAll units
1190+
return ()
1191+
}
11861192

11871193
/// Converts a Task into Task<unit>
1188-
let ToTaskUnit (t:Task) =
1189-
let continuation _ = ()
1194+
let inline ToTaskUnit (t:Task) =
1195+
let inline continuation _ = ()
11901196
t.ContinueWith continuation
11911197

11921198
/// Creates a task that runs the given task and ignores its result.
@@ -1219,7 +1225,6 @@ module Task =
12191225
let Parallel (tasks : seq<unit -> Task<'a>>) : (Task<'a[]>) =
12201226
tasks
12211227
|> Seq.map (fun t -> t())
1222-
|> Array.ofSeq
12231228
|> Task.WhenAll
12241229

12251230
/// Creates a task that executes all the given tasks.

0 commit comments

Comments
 (0)