Skip to content

Commit

Permalink
[v5] Comment Cleanup (#289)
Browse files Browse the repository at this point in the history
* Removed commented out code from legacy v4 functions

* Reverted changes to CancellableTaskOption since it isn't implemented yet

---------

Co-authored-by: Jimmy Byrd <[email protected]>
  • Loading branch information
1eyewonder and TheAngryByrd authored Dec 21, 2024
1 parent 6d15f0e commit a5d96b2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 553 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -697,15 +697,6 @@ module CancellableTaskResultBuilderBase =
continuation = (fun v -> this.Return v)
)


// [<NoEagerConstraintApplication>]
// member inline this.BindReturn
// (
// [<InlineIfLambda>] getAwaiterT: CancellationToken -> 'Awaiter,
// mapper: 'TResult1 -> 'TResult2
// ) : CancellableTaskResultBuilderBaseCode<_, _, _, _> =
// this.Bind((fun ct -> getAwaiterT ct), (fun v -> this.Return(mapper v)))

/// <summary>
/// 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.
/// </summary>
Expand Down Expand Up @@ -828,124 +819,12 @@ module CancellableTaskResultBuilderBase =
: CancellableTaskResultBuilderBaseCode<_, _, _, 'Builder> =
this.Bind(awaiterT = awaiterT, continuation = (fun v -> this.Return v))

// [<NoEagerConstraintApplication>]
// member inline this.BindReturn
// (
// awaiterT: 'Awaiter,
// [<InlineIfLambda>] mapper: 'a -> 'TResult2
// ) : CancellableTaskResultBuilderBaseCode<'TResult2, 'TResult2, 'Error, 'Builder> =
// this.Bind(awaiterT = awaiterT, continuation = (fun v -> this.Return(mapper v)))


/// <exclude/>
[<AutoOpen>]
module LowPriority =
// Low priority extensions
type CancellableTaskResultBuilderBase with

// /// <summary>
// /// 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.
// /// </summary>
// [<NoEagerConstraintApplication>]
// static member inline BindDynamic
// (
// sm:
// byref<ResumableStateMachine<CancellableTaskResultBuilderBaseStateMachineData<'TOverall, 'Error, 'Builder>>>,
// [<InlineIfLambda>] getAwaiter: CancellationToken -> 'Awaiter,
// continuation:
// ('TResult1
// -> CancellableTaskResultBuilderBaseCode<'TOverall, 'TResult2, 'Error, 'Builder>)
// ) : bool =
// sm.Data.ThrowIfCancellationRequested()

// let mutable awaiter = getAwaiter sm.Data.CancellationToken

// let cont =
// (CancellableTaskResultBuilderBaseResumptionFunc<'TOverall, 'Error, _>(fun sm ->
// let result = Awaiter.GetResult awaiter

// match result with
// | Ok result -> (continuation result).Invoke(&sm)
// | Error e ->
// sm.Data.Result <- Error e
// true
// ))

// // shortcut to continue immediately
// if Awaiter.IsCompleted awaiter then
// cont.Invoke(&sm)
// else
// sm.ResumptionDynamicInfo.ResumptionData <-
// (awaiter :> ICriticalNotifyCompletion)

// sm.ResumptionDynamicInfo.ResumptionFunc <- cont
// false

// /// <summary>Creates A CancellableTask that runs computation, and when
// /// computation generates a result T, runs binder res.</summary>
// ///
// /// <remarks>A cancellation check is performed when the computation is executed.
// ///
// /// The existence of this method permits the use of let! in the
// /// cancellableTask { ... } computation expression syntax.</remarks>
// ///
// /// <param name="getAwaiter">The computation to provide an unbound result.</param>
// /// <param name="continuation">The function to bind the result of computation.</param>
// ///
// /// <returns>A CancellableTask that performs a monadic bind on the result
// /// of computation.</returns>
// [<NoEagerConstraintApplication>]
// member inline _.Bind
// (
// [<InlineIfLambda>] getAwaiterTResult: CancellationToken -> 'Awaiter,
// continuation:
// ('TResult1
// -> CancellableTaskResultBuilderBaseCode<'TOverall, 'TResult2, 'Error, 'Builder>)
// ) : CancellableTaskResultBuilderBaseCode<'TOverall, 'TResult2, 'Error, 'Builder> =

// CancellableTaskResultBuilderBaseCode<'TOverall, 'TResult2, 'Error, 'Builder>(fun sm ->
// if __useResumableCode then
// //-- RESUMABLE CODE START
// sm.Data.ThrowIfCancellationRequested()
// // Get an awaiter from the Awaiter
// let mutable awaiter = getAwaiterTResult sm.Data.CancellationToken

// let mutable __stack_fin = true

// if not (Awaiter.IsCompleted awaiter) then
// // This will yield with __stack_yield_fin = false
// // This will resume with __stack_yield_fin = true
// let __stack_yield_fin = ResumableCode.Yield().Invoke(&sm)
// __stack_fin <- __stack_yield_fin

// if __stack_fin then
// let result = Awaiter.GetResult awaiter

// match result with
// | Ok result -> (continuation result).Invoke(&sm)
// | Error e ->
// sm.Data.Result <- Error e
// true
// else
// let mutable awaiter = awaiter :> ICriticalNotifyCompletion

// MethodBuilder.AwaitUnsafeOnCompleted(
// &sm.Data.MethodBuilder,
// &awaiter,
// &sm
// )

// false
// else
// CancellableTaskResultBuilderBase.BindDynamic(
// &sm,
// getAwaiterTResult,
// continuation
// )
// //-- RESUMABLE CODE END
// )


/// <summary>Delegates to the input computation.</summary>
///
/// <remarks>The existence of this method permits the use of return! in the
Expand All @@ -963,16 +842,6 @@ module CancellableTaskResultBuilderBase =
continuation = (fun v -> this.Return v)
)


// [<NoEagerConstraintApplication>]
// member inline this.BindReturn
// (
// [<InlineIfLambda>] getAwaiterTResult: CancellationToken -> 'Awaiter,
// mapper: 'TResult1 -> 'TResult2
// ) : CancellableTaskResultBuilderBaseCode<_, _, _, _> =
// this.Bind((fun ct -> getAwaiterTResult ct), (fun v -> this.Return(mapper v)))


/// <summary>Allows the computation expression to turn other types into CancellationToken -> 'Awaiter</summary>
///
/// <remarks>This turns a CancellationToken -> 'Awaitable into a CancellationToken -> 'Awaiter.</remarks>
Expand Down Expand Up @@ -1145,18 +1014,6 @@ module CancellableTaskResultBuilderBase =
: CancellableTaskResultBuilderBaseCode<_, _, _, 'Builder> =
this.Bind(awaiterTResult = awaiterTResult, continuation = (fun v -> this.Return v))

// [<NoEagerConstraintApplication>]
// member inline this.BindReturn
// (
// awaiterTResult: 'Awaiter,
// [<InlineIfLambda>] mapper: 'a -> 'TResult2
// ) : CancellableTaskResultBuilderBaseCode<'TResult2, 'TResult2, 'Error, 'Builder> =
// this.Bind(
// awaiterTResult = awaiterTResult,
// continuation = (fun v -> this.Return(mapper v))
// )


/// <summary>Allows the computation expression to turn other types into CancellationToken -> 'Awaiter</summary>
///
/// <remarks>This is the identify function.</remarks>
Expand Down Expand Up @@ -1298,71 +1155,6 @@ module CancellableTaskResultBuilderBase =
: Async<_> =
Async.AwaitCancellableTaskResult t


// type AsyncEx with

// /// <summary>Return an asynchronous computation that will wait for the given task to complete and return
// /// its result.</summary>
// ///
// /// <remarks>
// /// This is based on <see href="https://github.com/fsharp/fslang-suggestions/issues/840">Async.Await overload (esp. AwaitTask without throwing AggregateException)</see>
// /// </remarks>
// static member inline AwaitCancellableTask
// ([<InlineIfLambda>] t: CancellationToken -> Task<'T>)
// =
// asyncEx {
// let! ct = Async.CancellationToken
// return! t ct
// }

// /// <summary>Return an asynchronous computation that will wait for the given task to complete and return
// /// its result.</summary>
// ///
// /// <remarks>
// /// This is based on <see href="https://github.com/fsharp/fslang-suggestions/issues/840">Async.Await overload (esp. AwaitTask without throwing AggregateException)</see>
// /// </remarks>
// static member inline AwaitCancellableTask
// ([<InlineIfLambda>] t: CancellationToken -> Task)
// =
// asyncEx {
// let! ct = Async.CancellationToken
// return! t ct
// }

// type Microsoft.FSharp.Control.Async with

// /// <summary>Return an asynchronous computation that will wait for the given task to complete and return
// /// its result.</summary>
// static member inline AwaitCancellableTask
// ([<InlineIfLambda>] t: CancellationToken -> Task<'T>)
// =
// async {
// let! ct = Async.CancellationToken

// return!
// t ct
// |> Async.AwaitTask
// }

// /// <summary>Return an asynchronous computation that will wait for the given task to complete and return
// /// its result.</summary>
// static member inline AwaitCancellableTask
// ([<InlineIfLambda>] t: CancellationToken -> Task)
// =
// async {
// let! ct = Async.CancellationToken

// return!
// t ct
// |> Async.AwaitTask
// }

// /// <summary>Runs an asynchronous computation, starting on the current operating system thread.</summary>
// static member inline AsCancellableTask
// (computation: Async<'T>)
// : CancellationToken -> Task<_> =
// fun ct -> Async.StartImmediateAsTask(computation, cancellationToken = ct)

// High priority extensions
type CancellableTaskResultBuilderBase with

Expand Down
95 changes: 0 additions & 95 deletions src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -142,58 +142,6 @@ module CancellableTaskResultCE =
: CancellationToken -> Awaiter<TaskAwaiter<_>, _> =
fun ct -> Awaitable.GetTaskAwaiter(x ct)

// member inline this.MergeSources
// (
// [<InlineIfLambda>] left: CancellationToken -> 'Awaiter1,
// [<InlineIfLambda>] right: CancellationToken -> 'Awaiter2
// ) =
// this.Run(
// this.Bind(
// left,
// fun leftR -> this.BindReturn(right, (fun rightR -> struct (leftR, rightR)))
// )
// )
// >> Awaitable.GetTaskAwaiter


// member inline this.MergeSources
// (
// left: 'Awaiter1,
// [<InlineIfLambda>] right: CancellationToken -> 'Awaiter2
// ) =
// this.Run(
// this.Bind(
// left,
// fun leftR -> this.BindReturn(right, (fun rightR -> struct (leftR, rightR)))
// )
// )
// >> Awaitable.GetTaskAwaiter


// member inline this.MergeSources
// (
// [<InlineIfLambda>] left: CancellationToken -> 'Awaiter1,
// right: 'Awaiter2
// ) =
// this.Run(
// this.Bind(
// left,
// fun leftR -> this.BindReturn(right, (fun rightR -> struct (leftR, rightR)))
// )
// )
// >> Awaitable.GetTaskAwaiter


// member inline this.MergeSources(left: 'Awaiter1, right: 'Awaiter2) =
// this.Run(
// this.Bind(
// left,
// fun leftR -> this.BindReturn(right, (fun rightR -> struct (leftR, rightR)))
// )
// )
// >> Awaitable.GetTaskAwaiter


/// Contains methods to build CancellableTasks using the F# computation expression syntax
type BackgroundCancellableTaskResultBuilder() =

Expand Down Expand Up @@ -312,49 +260,6 @@ module CancellableTaskResultCE =
let backgroundCancellableTaskResult = BackgroundCancellableTaskResultBuilder()


// /// <summary>
// /// A set of extension methods making it possible to bind against <see cref='T:IcedTasks.CancellableTasks.CancellableTask`1'/> in async computations.
// /// </summary>
// [<AutoOpen>]
// module AsyncExtensions =

// type AsyncExBuilder with

// member inline this.Source([<InlineIfLambda>] t: CancellableTask<'T>) : Async<'T> =
// AsyncEx.AwaitCancellableTask t

// member inline this.Source([<InlineIfLambda>] t: CancellableTask) : Async<unit> =
// AsyncEx.AwaitCancellableTask t

// type Microsoft.FSharp.Control.AsyncBuilder with

// member inline this.Bind
// (
// [<InlineIfLambda>] t: CancellableTask<'T>,
// [<InlineIfLambda>] binder: ('T -> Async<'U>)
// ) : Async<'U> =
// this.Bind(Async.AwaitCancellableTask t, binder)

// member inline this.ReturnFrom([<InlineIfLambda>] t: CancellableTask<'T>) : Async<'T> =
// this.ReturnFrom(Async.AwaitCancellableTask t)

// member inline this.Bind
// (
// [<InlineIfLambda>] t: CancellableTask,
// [<InlineIfLambda>] binder: (unit -> Async<'U>)
// ) : Async<'U> =
// this.Bind(Async.AwaitCancellableTask t, binder)

// member inline this.ReturnFrom([<InlineIfLambda>] t: CancellableTask) : Async<unit> =
// this.ReturnFrom(Async.AwaitCancellableTask t)

// // There is explicitly no Binds for `CancellableTasks` in `Microsoft.FSharp.Control.TaskBuilderBase`.
// // You need to explicitly pass in a `CancellationToken`to start it, you can use `CancellationToken.None`.
// // Reason is I don't want people to assume cancellation is happening without the caller being explicit about where the CancellationToken came from.
// // Similar reasoning for `IcedTasks.ColdTasks.ColdTaskBuilderBase`.

// // Contains a set of standard functional helper function

[<RequireQualifiedAccess>]
module CancellableTaskResult =
open System.Threading.Tasks
Expand Down
Loading

0 comments on commit a5d96b2

Please sign in to comment.