@@ -102,13 +102,11 @@ module Async2Implementation =
102102
103103 member this.Ref : ICriticalNotifyCompletion ref = ref this
104104
105- member _.Running = running
106-
107105 member _.IsStackSufficient () =
108106 depth <- depth + 1
109107 depth % MaxDepth <> 0
110108
111- member _.ShouldBounce = pending.IsNone && insufficientStack ()
109+ member _.ShouldBounce = not running || pending.IsNone && insufficientStack ()
112110
113111 static member Current = holder.Value
114112
@@ -160,8 +158,8 @@ module Async2Implementation =
160158
161159 type Async2Code < 'TOverall , 'T > = ResumableCode< Async2Data< 'TOverall>, 'T>
162160
163- [<NoComparison>]
164- type Async2 < 't , 'm when 'm :> IAsyncStateMachine and 'm :> IAsync2StateMachine < 't >>() =
161+ [<Struct ; NoComparison>]
162+ type Async2 < 't , 'm when 'm :> IAsyncStateMachine and 'm :> IAsync2StateMachine < 't >> =
165163 [<DefaultValue( false ) >]
166164 val mutable StateMachine : 'm
167165
@@ -553,21 +551,12 @@ type Async2 =
553551 async2 {
554552 let! ct = Async2.CancellationToken
555553 use lcts = CancellationTokenSource.CreateLinkedTokenSource ct
556-
557- let tasks =
558- seq {
559- for c in computations do
560- async2 {
561- try
562- return ! c
563- with exn ->
564- lcts.Cancel()
565- return raise exn
566- }
567- |> Async2.startInThreadPool lcts.Token
568- }
569-
570- return ! Task.WhenAll tasks
554+ try
555+ let tasks = computations |> Seq.map ( Async2.startInThreadPool lcts.Token)
556+ return ! Task.WhenAll tasks
557+ with exn ->
558+ lcts.Cancel()
559+ return raise exn
571560 }
572561
573562 static member Sequential ( computations : Async2 < _ > seq ) =
0 commit comments