@@ -828,12 +828,124 @@ module CancellableTaskResultBuilderBase =
828828 : CancellableTaskResultBuilderBaseCode < _ , _ , _ , 'Builder > =
829829 this.Bind( awaiterT = awaiterT, continuation = ( fun v -> this.Return v))
830830
831+ // [<NoEagerConstraintApplication>]
832+ // member inline this.BindReturn
833+ // (
834+ // awaiterT: 'Awaiter,
835+ // [<InlineIfLambda>] mapper: 'a -> 'TResult2
836+ // ) : CancellableTaskResultBuilderBaseCode<'TResult2, 'TResult2, 'Error, 'Builder> =
837+ // this.Bind(awaiterT = awaiterT, continuation = (fun v -> this.Return(mapper v)))
838+
839+
831840 /// <exclude/>
832841 [<AutoOpen>]
833842 module LowPriority =
834843 // Low priority extensions
835844 type CancellableTaskResultBuilderBase with
836845
846+ // /// <summary>
847+ // /// The entry point for the dynamic implementation of the corresponding operation. Do not use directly, only used when executing quotations that involve tasks or other reflective execution of F# code.
848+ // /// </summary>
849+ // [<NoEagerConstraintApplication>]
850+ // static member inline BindDynamic
851+ // (
852+ // sm:
853+ // byref<ResumableStateMachine<CancellableTaskResultBuilderBaseStateMachineData<'TOverall, 'Error, 'Builder>>>,
854+ // [<InlineIfLambda>] getAwaiter: CancellationToken -> 'Awaiter,
855+ // continuation:
856+ // ('TResult1
857+ // -> CancellableTaskResultBuilderBaseCode<'TOverall, 'TResult2, 'Error, 'Builder>)
858+ // ) : bool =
859+ // sm.Data.ThrowIfCancellationRequested()
860+
861+ // let mutable awaiter = getAwaiter sm.Data.CancellationToken
862+
863+ // let cont =
864+ // (CancellableTaskResultBuilderBaseResumptionFunc<'TOverall, 'Error, _>(fun sm ->
865+ // let result = Awaiter.GetResult awaiter
866+
867+ // match result with
868+ // | Ok result -> (continuation result).Invoke(&sm)
869+ // | Error e ->
870+ // sm.Data.Result <- Error e
871+ // true
872+ // ))
873+
874+ // // shortcut to continue immediately
875+ // if Awaiter.IsCompleted awaiter then
876+ // cont.Invoke(&sm)
877+ // else
878+ // sm.ResumptionDynamicInfo.ResumptionData <-
879+ // (awaiter :> ICriticalNotifyCompletion)
880+
881+ // sm.ResumptionDynamicInfo.ResumptionFunc <- cont
882+ // false
883+
884+ // /// <summary>Creates A CancellableTask that runs computation, and when
885+ // /// computation generates a result T, runs binder res.</summary>
886+ // ///
887+ // /// <remarks>A cancellation check is performed when the computation is executed.
888+ // ///
889+ // /// The existence of this method permits the use of let! in the
890+ // /// cancellableTask { ... } computation expression syntax.</remarks>
891+ // ///
892+ // /// <param name="getAwaiter">The computation to provide an unbound result.</param>
893+ // /// <param name="continuation">The function to bind the result of computation.</param>
894+ // ///
895+ // /// <returns>A CancellableTask that performs a monadic bind on the result
896+ // /// of computation.</returns>
897+ // [<NoEagerConstraintApplication>]
898+ // member inline _.Bind
899+ // (
900+ // [<InlineIfLambda>] getAwaiterTResult: CancellationToken -> 'Awaiter,
901+ // continuation:
902+ // ('TResult1
903+ // -> CancellableTaskResultBuilderBaseCode<'TOverall, 'TResult2, 'Error, 'Builder>)
904+ // ) : CancellableTaskResultBuilderBaseCode<'TOverall, 'TResult2, 'Error, 'Builder> =
905+
906+ // CancellableTaskResultBuilderBaseCode<'TOverall, 'TResult2, 'Error, 'Builder>(fun sm ->
907+ // if __useResumableCode then
908+ // //-- RESUMABLE CODE START
909+ // sm.Data.ThrowIfCancellationRequested()
910+ // // Get an awaiter from the Awaiter
911+ // let mutable awaiter = getAwaiterTResult sm.Data.CancellationToken
912+
913+ // let mutable __stack_fin = true
914+
915+ // if not (Awaiter.IsCompleted awaiter) then
916+ // // This will yield with __stack_yield_fin = false
917+ // // This will resume with __stack_yield_fin = true
918+ // let __stack_yield_fin = ResumableCode.Yield().Invoke(&sm)
919+ // __stack_fin <- __stack_yield_fin
920+
921+ // if __stack_fin then
922+ // let result = Awaiter.GetResult awaiter
923+
924+ // match result with
925+ // | Ok result -> (continuation result).Invoke(&sm)
926+ // | Error e ->
927+ // sm.Data.Result <- Error e
928+ // true
929+ // else
930+ // let mutable awaiter = awaiter :> ICriticalNotifyCompletion
931+
932+ // MethodBuilder.AwaitUnsafeOnCompleted(
933+ // &sm.Data.MethodBuilder,
934+ // &awaiter,
935+ // &sm
936+ // )
937+
938+ // false
939+ // else
940+ // CancellableTaskResultBuilderBase.BindDynamic(
941+ // &sm,
942+ // getAwaiterTResult,
943+ // continuation
944+ // )
945+ // //-- RESUMABLE CODE END
946+ // )
947+
948+
837949 /// <summary>Delegates to the input computation.</summary>
838950 ///
839951 /// <remarks>The existence of this method permits the use of return! in the
@@ -851,6 +963,16 @@ module CancellableTaskResultBuilderBase =
851963 continuation = ( fun v -> this.Return v)
852964 )
853965
966+
967+ // [<NoEagerConstraintApplication>]
968+ // member inline this.BindReturn
969+ // (
970+ // [<InlineIfLambda>] getAwaiterTResult: CancellationToken -> 'Awaiter,
971+ // mapper: 'TResult1 -> 'TResult2
972+ // ) : CancellableTaskResultBuilderBaseCode<_, _, _, _> =
973+ // this.Bind((fun ct -> getAwaiterTResult ct), (fun v -> this.Return(mapper v)))
974+
975+
854976 /// <summary>Allows the computation expression to turn other types into CancellationToken -> 'Awaiter</summary>
855977 ///
856978 /// <remarks>This turns a CancellationToken -> 'Awaitable into a CancellationToken -> 'Awaiter.</remarks>
@@ -1023,6 +1145,18 @@ module CancellableTaskResultBuilderBase =
10231145 : CancellableTaskResultBuilderBaseCode < _ , _ , _ , 'Builder > =
10241146 this.Bind( awaiterTResult = awaiterTResult, continuation = ( fun v -> this.Return v))
10251147
1148+ // [<NoEagerConstraintApplication>]
1149+ // member inline this.BindReturn
1150+ // (
1151+ // awaiterTResult: 'Awaiter,
1152+ // [<InlineIfLambda>] mapper: 'a -> 'TResult2
1153+ // ) : CancellableTaskResultBuilderBaseCode<'TResult2, 'TResult2, 'Error, 'Builder> =
1154+ // this.Bind(
1155+ // awaiterTResult = awaiterTResult,
1156+ // continuation = (fun v -> this.Return(mapper v))
1157+ // )
1158+
1159+
10261160 /// <summary>Allows the computation expression to turn other types into CancellationToken -> 'Awaiter</summary>
10271161 ///
10281162 /// <remarks>This is the identify function.</remarks>
@@ -1164,6 +1298,71 @@ module CancellableTaskResultBuilderBase =
11641298 : Async < _ > =
11651299 Async.AwaitCancellableTaskResult t
11661300
1301+
1302+ // type AsyncEx with
1303+
1304+ // /// <summary>Return an asynchronous computation that will wait for the given task to complete and return
1305+ // /// its result.</summary>
1306+ // ///
1307+ // /// <remarks>
1308+ // /// This is based on <see href="https://github.com/fsharp/fslang-suggestions/issues/840">Async.Await overload (esp. AwaitTask without throwing AggregateException)</see>
1309+ // /// </remarks>
1310+ // static member inline AwaitCancellableTask
1311+ // ([<InlineIfLambda>] t: CancellationToken -> Task<'T>)
1312+ // =
1313+ // asyncEx {
1314+ // let! ct = Async.CancellationToken
1315+ // return! t ct
1316+ // }
1317+
1318+ // /// <summary>Return an asynchronous computation that will wait for the given task to complete and return
1319+ // /// its result.</summary>
1320+ // ///
1321+ // /// <remarks>
1322+ // /// This is based on <see href="https://github.com/fsharp/fslang-suggestions/issues/840">Async.Await overload (esp. AwaitTask without throwing AggregateException)</see>
1323+ // /// </remarks>
1324+ // static member inline AwaitCancellableTask
1325+ // ([<InlineIfLambda>] t: CancellationToken -> Task)
1326+ // =
1327+ // asyncEx {
1328+ // let! ct = Async.CancellationToken
1329+ // return! t ct
1330+ // }
1331+
1332+ // type Microsoft.FSharp.Control.Async with
1333+
1334+ // /// <summary>Return an asynchronous computation that will wait for the given task to complete and return
1335+ // /// its result.</summary>
1336+ // static member inline AwaitCancellableTask
1337+ // ([<InlineIfLambda>] t: CancellationToken -> Task<'T>)
1338+ // =
1339+ // async {
1340+ // let! ct = Async.CancellationToken
1341+
1342+ // return!
1343+ // t ct
1344+ // |> Async.AwaitTask
1345+ // }
1346+
1347+ // /// <summary>Return an asynchronous computation that will wait for the given task to complete and return
1348+ // /// its result.</summary>
1349+ // static member inline AwaitCancellableTask
1350+ // ([<InlineIfLambda>] t: CancellationToken -> Task)
1351+ // =
1352+ // async {
1353+ // let! ct = Async.CancellationToken
1354+
1355+ // return!
1356+ // t ct
1357+ // |> Async.AwaitTask
1358+ // }
1359+
1360+ // /// <summary>Runs an asynchronous computation, starting on the current operating system thread.</summary>
1361+ // static member inline AsCancellableTask
1362+ // (computation: Async<'T>)
1363+ // : CancellationToken -> Task<_> =
1364+ // fun ct -> Async.StartImmediateAsTask(computation, cancellationToken = ct)
1365+
11671366 // High priority extensions
11681367 type CancellableTaskResultBuilderBase with
11691368
0 commit comments