@@ -90,7 +90,7 @@ type Trampoline(cancellationToken: CancellationToken) =
90
90
let mutable bindDepth = 0
91
91
92
92
[<Literal>]
93
- static let bindDepthLimit = 1000
93
+ static let bindDepthLimit = 100
94
94
95
95
static let current = new ThreadLocal< Trampoline>()
96
96
@@ -101,8 +101,7 @@ type Trampoline(cancellationToken: CancellationToken) =
101
101
member this.ThrowIfCancellationRequested () =
102
102
cancellationToken.ThrowIfCancellationRequested()
103
103
104
- member this.ShoudBounce =
105
- bindDepth % bindDepthLimit = 0
104
+ member this.ShoudBounce = bindDepth % bindDepthLimit = 0
106
105
107
106
static member Install ct = current.Value <- Trampoline ct
108
107
@@ -116,7 +115,8 @@ type Trampoline(cancellationToken: CancellationToken) =
116
115
117
116
member this.RunImmediate ( invocation : ITrampolineInvocation ) =
118
117
bindDepth <- bindDepth + 1
119
- try
118
+
119
+ try
120
120
// This can throw, which is fine. We want the exception to propagate to the calling machine.
121
121
invocation.MoveNext()
122
122
@@ -130,7 +130,6 @@ type Trampoline(cancellationToken: CancellationToken) =
130
130
finally
131
131
bindDepth <- bindDepth - 1
132
132
133
-
134
133
static member Current = current.Value
135
134
136
135
type ITrampolineInvocation < 'T > =
@@ -140,7 +139,9 @@ type ITrampolineInvocation<'T> =
140
139
[<AutoOpen>]
141
140
module ExceptionDispatchInfoHelpers =
142
141
type ExceptionDispatchInfo with
143
- member edi.ThrowAny () = edi.Throw(); Unchecked.defaultof<_>
142
+ member edi.ThrowAny () =
143
+ edi.Throw()
144
+ Unchecked.defaultof<_>
144
145
145
146
static member RestoreOrCapture ( exn : exn ) =
146
147
match Trampoline.Current.LastError with
@@ -155,20 +156,19 @@ type ICancellableInvokable<'T> =
155
156
abstract Create: bool -> ITrampolineInvocation < 'T >
156
157
157
158
[<NoEquality; NoComparison>]
158
- type CancellableInvocation < 'T , 'Machine when 'Machine :> IAsyncStateMachine and 'Machine :> ICancellableStateMachine < 'T >>( machine : 'Machine , delayed : bool )
159
- =
159
+ type CancellableInvocation < 'T , 'Machine when 'Machine :> IAsyncStateMachine and 'Machine :> ICancellableStateMachine < 'T >>
160
+ ( machine : 'Machine , delayed : bool ) =
160
161
let mutable machine = machine
161
162
let mutable storedException = ValueNone
162
163
let mutable finished = false
163
164
164
- new ( machine ) = CancellableInvocation( machine, false )
165
+ new ( machine) = CancellableInvocation( machine, false )
165
166
166
167
interface ITrampolineInvocation< 'T> with
167
168
member this.MoveNext () =
168
169
let pushDelayed () =
169
170
match machine.Data.NextInvocation with
170
- | ValueSome delayed ->
171
- Trampoline.Current.RunDelayed( this, delayed)
171
+ | ValueSome delayed -> Trampoline.Current.RunDelayed( this, delayed)
172
172
| _ -> finished <- true
173
173
174
174
if delayed then
@@ -185,16 +185,19 @@ type CancellableInvocation<'T, 'Machine when 'Machine :> IAsyncStateMachine and
185
185
186
186
member _.Result = machine.Data.Result
187
187
member _.IsCompleted = finished
188
- member _.ReplayExceptionIfStored () = storedException |> ValueOption.iter _. Throw()
188
+
189
+ member _.ReplayExceptionIfStored () =
190
+ storedException |> ValueOption.iter _. Throw()
189
191
190
192
interface ICancellableInvokable< 'T> with
191
- member _.Create ( delayed ) = CancellableInvocation<_, _>( machine, delayed)
193
+ member _.Create ( delayed ) =
194
+ CancellableInvocation<_, _>( machine, delayed)
192
195
193
196
[<Struct; NoComparison>]
194
197
type Cancellable < 'T >( invokable : ICancellableInvokable < 'T >) =
195
-
198
+
196
199
member _.GetInvocation ( delayed ) = invokable.Create( delayed)
197
-
200
+
198
201
[<AutoOpen>]
199
202
module CancellableCode =
200
203
@@ -263,8 +266,7 @@ type CancellableBuilder() =
263
266
: CancellableCode < 'Data , 'T > =
264
267
CancellableCode( fun sm ->
265
268
if __ useResumableCode then
266
- let mutable invocation =
267
- code.GetInvocation Trampoline.Current.ShoudBounce
269
+ let mutable invocation = code.GetInvocation Trampoline.Current.ShoudBounce
268
270
269
271
if Trampoline.Current.ShoudBounce then
270
272
// Suspend this state machine and schedule both parts to run on the trampoline.
@@ -314,8 +316,7 @@ type CancellableBuilder() =
314
316
let __stack_code_fin = code.Invoke(& sm)
315
317
316
318
if __ stack_ code_ fin then
317
- sm.ResumptionPoint <- - 1
318
- ))
319
+ sm.ResumptionPoint <- - 1 ))
319
320
320
321
( SetStateMachineMethodImpl<_>( fun _ _ -> ()))
321
322
@@ -338,7 +339,6 @@ type CancellableBuilder() =
338
339
339
340
Cancellable( CancellableInvocation( sm))
340
341
341
-
342
342
namespace Internal.Utilities.Library
343
343
344
344
open System
0 commit comments