Skip to content

Commit 7c2ea7c

Browse files
committed
Reverted comment cleanup meant for other PR
1 parent c33eabf commit 7c2ea7c

File tree

3 files changed

+547
-0
lines changed

3 files changed

+547
-0
lines changed

src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultBuilderBase.fs

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultCE.fs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,58 @@ module CancellableTaskResultCE =
142142
: CancellationToken -> Awaiter<TaskAwaiter<_>, _> =
143143
fun ct -> Awaitable.GetTaskAwaiter(x ct)
144144

145+
// member inline this.MergeSources
146+
// (
147+
// [<InlineIfLambda>] left: CancellationToken -> 'Awaiter1,
148+
// [<InlineIfLambda>] right: CancellationToken -> 'Awaiter2
149+
// ) =
150+
// this.Run(
151+
// this.Bind(
152+
// left,
153+
// fun leftR -> this.BindReturn(right, (fun rightR -> struct (leftR, rightR)))
154+
// )
155+
// )
156+
// >> Awaitable.GetTaskAwaiter
157+
158+
159+
// member inline this.MergeSources
160+
// (
161+
// left: 'Awaiter1,
162+
// [<InlineIfLambda>] right: CancellationToken -> 'Awaiter2
163+
// ) =
164+
// this.Run(
165+
// this.Bind(
166+
// left,
167+
// fun leftR -> this.BindReturn(right, (fun rightR -> struct (leftR, rightR)))
168+
// )
169+
// )
170+
// >> Awaitable.GetTaskAwaiter
171+
172+
173+
// member inline this.MergeSources
174+
// (
175+
// [<InlineIfLambda>] left: CancellationToken -> 'Awaiter1,
176+
// right: 'Awaiter2
177+
// ) =
178+
// this.Run(
179+
// this.Bind(
180+
// left,
181+
// fun leftR -> this.BindReturn(right, (fun rightR -> struct (leftR, rightR)))
182+
// )
183+
// )
184+
// >> Awaitable.GetTaskAwaiter
185+
186+
187+
// member inline this.MergeSources(left: 'Awaiter1, right: 'Awaiter2) =
188+
// this.Run(
189+
// this.Bind(
190+
// left,
191+
// fun leftR -> this.BindReturn(right, (fun rightR -> struct (leftR, rightR)))
192+
// )
193+
// )
194+
// >> Awaitable.GetTaskAwaiter
195+
196+
145197
/// Contains methods to build CancellableTasks using the F# computation expression syntax
146198
type BackgroundCancellableTaskResultBuilder() =
147199

@@ -259,6 +311,50 @@ module CancellableTaskResultCE =
259311
/// </summary>
260312
let backgroundCancellableTaskResult = BackgroundCancellableTaskResultBuilder()
261313

314+
315+
// /// <summary>
316+
// /// A set of extension methods making it possible to bind against <see cref='T:IcedTasks.CancellableTasks.CancellableTask`1'/> in async computations.
317+
// /// </summary>
318+
// [<AutoOpen>]
319+
// module AsyncExtensions =
320+
321+
// type AsyncExBuilder with
322+
323+
// member inline this.Source([<InlineIfLambda>] t: CancellableTask<'T>) : Async<'T> =
324+
// AsyncEx.AwaitCancellableTask t
325+
326+
// member inline this.Source([<InlineIfLambda>] t: CancellableTask) : Async<unit> =
327+
// AsyncEx.AwaitCancellableTask t
328+
329+
// type Microsoft.FSharp.Control.AsyncBuilder with
330+
331+
// member inline this.Bind
332+
// (
333+
// [<InlineIfLambda>] t: CancellableTask<'T>,
334+
// [<InlineIfLambda>] binder: ('T -> Async<'U>)
335+
// ) : Async<'U> =
336+
// this.Bind(Async.AwaitCancellableTask t, binder)
337+
338+
// member inline this.ReturnFrom([<InlineIfLambda>] t: CancellableTask<'T>) : Async<'T> =
339+
// this.ReturnFrom(Async.AwaitCancellableTask t)
340+
341+
// member inline this.Bind
342+
// (
343+
// [<InlineIfLambda>] t: CancellableTask,
344+
// [<InlineIfLambda>] binder: (unit -> Async<'U>)
345+
// ) : Async<'U> =
346+
// this.Bind(Async.AwaitCancellableTask t, binder)
347+
348+
// member inline this.ReturnFrom([<InlineIfLambda>] t: CancellableTask) : Async<unit> =
349+
// this.ReturnFrom(Async.AwaitCancellableTask t)
350+
351+
// // There is explicitly no Binds for `CancellableTasks` in `Microsoft.FSharp.Control.TaskBuilderBase`.
352+
// // You need to explicitly pass in a `CancellationToken`to start it, you can use `CancellationToken.None`.
353+
// // Reason is I don't want people to assume cancellation is happening without the caller being explicit about where the CancellationToken came from.
354+
// // Similar reasoning for `IcedTasks.ColdTasks.ColdTaskBuilderBase`.
355+
356+
// // Contains a set of standard functional helper function
357+
262358
[<RequireQualifiedAccess>]
263359
module CancellableTaskResult =
264360
open System.Threading.Tasks

0 commit comments

Comments
 (0)