@@ -38,11 +38,6 @@ module Extensions =
3838 open System.Threading .Tasks
3939 open FSharp.Core .CompilerServices
4040
41- let private (| Canceled | Faulted | Completed |) ( t : Task < 'a >) =
42- if t.IsCanceled then Canceled
43- else if t.IsFaulted then Faulted ( Unchecked.nonNull t.Exception)
44- else Completed t.Result
45-
4641 type Task < 't > with
4742 static member WhenAll ( tasks : Task < 'a >[], ? cancellationToken : CancellationToken ) =
4843 let tcs = TaskCompletionSource< 'a[]> ()
@@ -53,9 +48,9 @@ module Extensions =
5348 tasks
5449 |> Seq.iteri ( fun i t ->
5550 let continuation = function
56- | Canceled -> tcs.TrySetCanceled () |> ignore
57- | Faulted e -> tcs.TrySetException e |> ignore
58- | Completed r ->
51+ | Task. Canceled -> tcs.TrySetCanceled () |> ignore
52+ | Task. Faulted e -> tcs.TrySetException e |> ignore
53+ | Task.Succeeded r ->
5954 results.[ i] <- r
6055 if Interlocked.Decrement pending = 0 then
6156 tcs.SetResult results
@@ -132,7 +127,7 @@ module Extensions =
132127 computation,
133128 ts.SetResult,
134129 ( function
135- | :? AggregateException as agg -> ts.SetException agg .InnerExceptions
130+ | :? AggregateException as aex when aex.InnerExceptions.Count > 0 -> ts.SetException aex .InnerExceptions
136131 | exn -> ts.SetException exn),
137132 ( fun _ -> ts.SetCanceled ()),
138133 cancellationToken)
@@ -198,7 +193,7 @@ module Extensions =
198193 /// Similar to Async.Sequential but the returned Async contains a sequence, which is lazily evaluated.
199194 static member SequentialLazy ( t : seq < Async < 'T >>) : Async < seq < _ >> = async {
200195 let! ct = Async.CancellationToken
201- return Seq.map ( fun t -> Async.AsTask( t, ct). Result ) t }
196+ return Seq.map ( fun t -> Async.AsTask( t, ct). GetAwaiter () .GetResult () ) t }
202197 [<Obsolete( " Renamed to Async.Sequential or Async.SequentialLazy" ) >] static member Sequence ( t : seq < Async < _ >>) = Async.SequentialLazy t
203198 #endif
204199
0 commit comments