11namespace FsToolkit.ErrorHandling
22
33
4-
54[<AutoOpen>]
65module CancellableTaskResultCE =
76
@@ -53,7 +52,6 @@ module CancellableTaskResultCE =
5352 ResumableCode< CancellableTaskResultStateMachineData< 'TOverall, 'Error>, 'T>
5453
5554
56-
5755 module CancellableTaskResultBuilderBase =
5856
5957 let rec WhileDynamic
@@ -126,7 +124,6 @@ module CancellableTaskResultCE =
126124 true )
127125
128126
129-
130127 static member inline CombineDynamic
131128 (
132129 sm : byref < CancellableTaskResultStateMachine < _ , _ >>,
@@ -182,7 +179,6 @@ module CancellableTaskResultCE =
182179 CancellableTaskResultBuilderBase.CombineDynamic(& sm, task1, task2))
183180
184181
185-
186182 /// Builds a step that executes the body while the condition predicate is true.
187183 member inline _.While
188184 (
@@ -194,9 +190,7 @@ module CancellableTaskResultCE =
194190 //-- RESUMABLE CODE START
195191 let mutable __stack_go = true
196192
197- while __ stack_ go
198- && not sm.Data.IsResultError
199- && condition () do
193+ while __ stack_ go && not sm.Data.IsResultError && condition () do
200194 // NOTE: The body of the state machine code for 'while' may contain await points, so resuming
201195 // the code will branch directly into the expanded 'body', branching directly into the while loop
202196 let __stack_body_fin = body.Invoke(& sm)
@@ -369,8 +363,8 @@ module CancellableTaskResultCE =
369363 assert not ( isNull awaiter)
370364 sm.Data.MethodBuilder.AwaitUnsafeOnCompleted(& awaiter, & sm)
371365
372- with
373- | exn -> savedExn <- exn
366+ with exn ->
367+ savedExn <- exn
374368 // Run SetException outside the stack unwind, see https://github.com/dotnet/roslyn/issues/26567
375369 match savedExn with
376370 | null -> ()
@@ -405,8 +399,8 @@ module CancellableTaskResultCE =
405399
406400 if __ stack_ code_ fin && not sm.Data.IsTaskCompleted then
407401 sm.Data.MethodBuilder.SetResult( sm.Data.Result)
408- with
409- | exn -> __ stack_ exn <- exn
402+ with exn ->
403+ __ stack_ exn <- exn
410404 // Run SetException outside the stack unwind, see https://github.com/dotnet/roslyn/issues/26567
411405 match __ stack_ exn with
412406 | null -> ()
@@ -462,8 +456,7 @@ module CancellableTaskResultCE =
462456
463457 if __ stack_ code_ fin && not sm.Data.IsTaskCompleted then
464458 sm.Data.MethodBuilder.SetResult( sm.Data.Result)
465- with
466- | exn ->
459+ with exn ->
467460
468461 // printfn "%A" exn
469462 sm.Data.MethodBuilder.SetException exn
@@ -524,9 +517,11 @@ module CancellableTaskResultCE =
524517 type CancellableTaskResultBuilderBase with
525518
526519 [<NoEagerConstraintApplication>]
527- static member inline BindDynamic < ^TaskLike , 'TResult1 , 'TResult2 , ^Awaiter , 'TOverall , 'Error when ^TaskLike : ( member GetAwaiter :
528- unit -> ^Awaiter ) and ^Awaiter :> ICriticalNotifyCompletion and ^Awaiter : ( member get_IsCompleted :
529- unit -> bool ) and ^Awaiter : ( member GetResult : unit -> Result<'TResult1 , 'Error > )>
520+ static member inline BindDynamic < ^TaskLike , 'TResult1 , 'TResult2 , ^Awaiter , 'TOverall , 'Error
521+ when ^TaskLike : ( member GetAwaiter : unit -> ^Awaiter )
522+ and ^Awaiter :> ICriticalNotifyCompletion
523+ and ^Awaiter : ( member get_IsCompleted : unit -> bool )
524+ and ^Awaiter : ( member GetResult : unit -> Result<'TResult1 , 'Error > )>
530525 (
531526 sm : byref < ResumableStateMachine < CancellableTaskResultStateMachineData < 'TOverall , 'Error >>>,
532527 task : CancellationToken -> ^TaskLike ,
@@ -557,9 +552,11 @@ module CancellableTaskResultCE =
557552 false
558553
559554 [<NoEagerConstraintApplication>]
560- member inline _.Bind < ^TaskLike , 'TResult1 , 'TResult2 , ^Awaiter , 'TOverall , 'Error when ^TaskLike : ( member GetAwaiter :
561- unit -> ^Awaiter ) and ^Awaiter :> ICriticalNotifyCompletion and ^Awaiter : ( member get_IsCompleted :
562- unit -> bool ) and ^Awaiter : ( member GetResult : unit -> Result<'TResult1 , 'Error > )>
555+ member inline _.Bind < ^TaskLike , 'TResult1 , 'TResult2 , ^Awaiter , 'TOverall , 'Error
556+ when ^TaskLike : ( member GetAwaiter : unit -> ^Awaiter )
557+ and ^Awaiter :> ICriticalNotifyCompletion
558+ and ^Awaiter : ( member get_IsCompleted : unit -> bool )
559+ and ^Awaiter : ( member GetResult : unit -> Result<'TResult1 , 'Error > )>
563560 (
564561 task : CancellationToken -> ^TaskLike ,
565562 continuation : ( 'TResult1 -> CancellableTaskResultCode < 'TOverall , 'Error , 'TResult2 >)
@@ -603,9 +600,11 @@ module CancellableTaskResultCE =
603600 )
604601
605602 [<NoEagerConstraintApplication>]
606- static member inline BindDynamic < ^TaskLike , 'TResult1 , 'TResult2 , ^Awaiter , 'TOverall , 'Error when ^TaskLike : ( member GetAwaiter :
607- unit -> ^Awaiter ) and ^Awaiter :> ICriticalNotifyCompletion and ^Awaiter : ( member get_IsCompleted :
608- unit -> bool ) and ^Awaiter : ( member GetResult : unit -> 'TResult1 )>
603+ static member inline BindDynamic < ^TaskLike , 'TResult1 , 'TResult2 , ^Awaiter , 'TOverall , 'Error
604+ when ^TaskLike : ( member GetAwaiter : unit -> ^Awaiter )
605+ and ^Awaiter :> ICriticalNotifyCompletion
606+ and ^Awaiter : ( member get_IsCompleted : unit -> bool )
607+ and ^Awaiter : ( member GetResult : unit -> 'TResult1 )>
609608 (
610609 sm : byref < ResumableStateMachine < CancellableTaskResultStateMachineData < 'TOverall , 'Error >>>,
611610 task : ^TaskLike ,
@@ -630,9 +629,11 @@ module CancellableTaskResultCE =
630629 false
631630
632631 [<NoEagerConstraintApplication>]
633- member inline this.Bind < ^TaskLike , 'TResult1 , 'TResult2 , ^Awaiter , 'TOverall , 'Error when ^TaskLike : ( member GetAwaiter :
634- unit -> ^Awaiter ) and ^Awaiter :> ICriticalNotifyCompletion and ^Awaiter : ( member get_IsCompleted :
635- unit -> bool ) and ^Awaiter : ( member GetResult : unit -> 'TResult1 )>
632+ member inline this.Bind < ^TaskLike , 'TResult1 , 'TResult2 , ^Awaiter , 'TOverall , 'Error
633+ when ^TaskLike : ( member GetAwaiter : unit -> ^Awaiter )
634+ and ^Awaiter :> ICriticalNotifyCompletion
635+ and ^Awaiter : ( member get_IsCompleted : unit -> bool )
636+ and ^Awaiter : ( member GetResult : unit -> 'TResult1 )>
636637 (
637638 task : ^TaskLike ,
638639 continuation : ( 'TResult1 -> CancellableTaskResultCode < 'TOverall , 'Error , 'TResult2 >)
@@ -674,9 +675,11 @@ module CancellableTaskResultCE =
674675 )
675676
676677 [<NoEagerConstraintApplication>]
677- member inline this.ReturnFrom < ^TaskLike , ^Awaiter , 'T , 'Error when ^TaskLike : ( member GetAwaiter :
678- unit -> ^Awaiter ) and ^Awaiter :> ICriticalNotifyCompletion and ^Awaiter : ( member get_IsCompleted :
679- unit -> bool ) and ^Awaiter : ( member GetResult : unit -> 'T )>
678+ member inline this.ReturnFrom < ^TaskLike , ^Awaiter , 'T , 'Error
679+ when ^TaskLike : ( member GetAwaiter : unit -> ^Awaiter )
680+ and ^Awaiter :> ICriticalNotifyCompletion
681+ and ^Awaiter : ( member get_IsCompleted : unit -> bool )
682+ and ^Awaiter : ( member GetResult : unit -> 'T )>
680683 ( task : ^TaskLike )
681684 : CancellableTaskResultCode < 'T , 'Error , 'T > =
682685
@@ -690,11 +693,10 @@ module CancellableTaskResultCE =
690693 ResumableCode.Using( resource, body)
691694
692695
693-
694-
695696 [<AutoOpen>]
696697 module HighPriority =
697698 type Microsoft.FSharp.Control.Async with
699+
698700 static member inline AwaitCancellableTaskResult ( [<InlineIfLambda>] t : CancellableTaskResult < 'T , 'Error >) = async {
699701 let! ct = Async.CancellationToken
700702 return ! t ct |> Async.AwaitTask
@@ -704,13 +706,14 @@ module CancellableTaskResultCE =
704706 fun ct -> Async.StartAsTask( computation, cancellationToken = ct)
705707
706708
707-
708-
709709 type CancellableTaskResultBuilder with
710710
711711 [<NoEagerConstraintApplication>]
712- member inline this.Source < ^TaskLike , ^Awaiter , 'T when ^TaskLike : ( member GetAwaiter : unit -> ^Awaiter ) and ^Awaiter :> ICriticalNotifyCompletion and ^Awaiter : ( member get_IsCompleted :
713- unit -> bool ) and ^Awaiter : ( member GetResult : unit -> 'T )>
712+ member inline this.Source < ^TaskLike , ^Awaiter , 'T
713+ when ^TaskLike : ( member GetAwaiter : unit -> ^Awaiter )
714+ and ^Awaiter :> ICriticalNotifyCompletion
715+ and ^Awaiter : ( member get_IsCompleted : unit -> bool )
716+ and ^Awaiter : ( member GetResult : unit -> 'T )>
714717 ( t : ^TaskLike )
715718 : CancellableTaskResult < _ , _ > =
716719 // : CancellableTaskResultCode<_,_,_> =
@@ -807,7 +810,6 @@ module CancellableTaskResultCE =
807810 this.Bind(( task), ( fun v -> this.Return v))
808811
809812
810-
811813 [<AutoOpen>]
812814 module MediumPriority =
813815 open HighPriority
@@ -853,6 +855,7 @@ module CancellableTaskResultCE =
853855
854856 // Medium priority extensions
855857 type CancellableTaskResultBuilderBase with
858+
856859 member inline this.Source ( t : Async < 'T >) : CancellableTaskResult < 'T , 'Error > =
857860 fun ct ->
858861 let t = t |> Async.map Ok
@@ -862,6 +865,7 @@ module CancellableTaskResultCE =
862865 [<AutoOpen>]
863866 module AsyncExtenions =
864867 type Microsoft.FSharp.Control.AsyncBuilder with
868+
865869 member inline this.Bind
866870 (
867871 [<InlineIfLambda>] t : CancellableTaskResult < 'T , 'Error >,
@@ -874,6 +878,7 @@ module CancellableTaskResultCE =
874878
875879
876880 type FsToolkit.ErrorHandling.AsyncResultCE.AsyncResultBuilder with
881+
877882 member inline this.Source ( [<InlineIfLambda>] t : CancellableTaskResult < 'T , 'Error >) : Async < _ > =
878883 Async.AwaitCancellableTaskResult t
879884
0 commit comments