Skip to content

Commit

Permalink
Removed commented out code from legacy v4 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
1eyewonder committed Dec 17, 2024
1 parent edc9ae0 commit f2eae40
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 661 deletions.
107 changes: 0 additions & 107 deletions src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskOption.fs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ type ValueTaskValueOptionBuilderBase() =
: CancellableValueTaskValueOption<'T> =
taskOption

// member inline this.Source(taskOption: ValueTask<'T option>) : CancellableTaskOption<'T> =
// taskOption.AsTask()


type ValueTaskValueOptionBuilder() =

inherit ValueTaskValueOptionBuilderBase()
Expand Down Expand Up @@ -355,76 +351,6 @@ type TaskOptionBuilder() =
return ValueOption.toOption r
}


// type BackgroundTaskOptionBuilder() =

// inherit TaskOptionBuilderBase()

// static member RunDynamic(code: TaskOptionCode<'T, 'T>) : CancellableTaskOption<'T> =
// // backgroundTask { .. } escapes to a background thread where necessary
// // See spec of ConfigureAwait(false) at https://devblogs.microsoft.com/dotnet/configureawait-faq/
// if
// isNull SynchronizationContext.Current
// && obj.ReferenceEquals(TaskScheduler.Current, TaskScheduler.Default)
// then
// TaskOptionBuilder.RunDynamic(code)
// else
// Task.Run<'T option>(fun () -> TaskOptionBuilder.RunDynamic(code))


// //// Same as TaskBuilder.Run except the start is inside Task.Run if necessary
// member inline _.Run(code: TaskOptionCode<'T, 'T>) : CancellableTaskOption<'T> =
// if __useResumableCode then
// __stateMachine<TaskOptionStateMachineData<'T>, CancellableTaskOption<'T>>
// (MoveNextMethodImpl<_>(fun sm ->
// //-- RESUMABLE CODE START
// __resumeAt sm.ResumptionPoint

// try
// let __stack_code_fin = code.Invoke(&sm)

// if
// __stack_code_fin
// && not sm.Data.IsTaskCompleted
// then
// sm.Data.MethodBuilder.SetResult(sm.Data.Result.Value)
// with exn ->
// sm.Data.MethodBuilder.SetException exn
// //-- RESUMABLE CODE END
// ))
// (SetStateMachineMethodImpl<_>(fun sm state ->
// sm.Data.MethodBuilder.SetStateMachine(state)
// ))
// (AfterCode<_, CancellableTaskOption<'T>>(fun sm ->
// // backgroundTask { .. } escapes to a background thread where necessary
// // See spec of ConfigureAwait(false) at https://devblogs.microsoft.com/dotnet/configureawait-faq/
// if
// isNull SynchronizationContext.Current
// && obj.ReferenceEquals(TaskScheduler.Current, TaskScheduler.Default)
// then
// sm.Data.MethodBuilder <- AsyncTaskOptionMethodBuilder<'T>.Create()
// sm.Data.MethodBuilder.Start(&sm)
// sm.Data.MethodBuilder.Task
// else
// let sm = sm // copy contents of state machine so we can capture it

// Task.Run<'T option>(fun () ->
// let mutable sm = sm // host local mutable copy of contents of state machine on this thread pool thread
// sm.Data.MethodBuilder <- AsyncTaskOptionMethodBuilder<'T>.Create()
// sm.Data.MethodBuilder.Start(&sm)
// sm.Data.MethodBuilder.Task
// )
// ))
// else
// BackgroundTaskOptionBuilder.RunDynamic(code)

// [<AutoOpen>]
// module TaskOptionBuilder =

// let taskOption = ValueTaskValueOptionBuilder()
// let backgroundTaskOption = BackgroundTaskOptionBuilder()


[<AutoOpen>]
module TaskOptionCEExtensionsLowPriority =
// Low priority extensions
Expand Down Expand Up @@ -626,36 +552,3 @@ module TaskOptionCEExtensionsHighPriority =
this.Bind(task, (fun v -> this.Return v))

member inline _.Source(s: #seq<_>) = s

// [<AutoOpen>]
// module TaskOptionCEExtensionsMediumPriority =

// // Medium priority extensions
// type TaskOptionBuilderBase with

// member inline this.Source(t: Task<'T>) : CancellableTaskOption<'T> =
// t
// |> Task.map Some

// member inline this.Source(t: Task) : CancellableTaskOption<unit> =
// task {
// do! t
// return Some()
// }

// member inline this.Source(t: ValueTask<'T>) : CancellableTaskOption<'T> =
// t
// |> Task.mapV Some

// member inline this.Source(t: ValueTask) : CancellableTaskOption<unit> =
// task {
// do! t
// return Some()
// }

// member inline this.Source(opt: Option<'T>) : CancellableTaskOption<'T> = Task.FromResult opt

// member inline this.Source(computation: Async<'T>) : CancellableTaskOption<'T> =
// computation
// |> Async.map Some
// |> Async.StartImmediateAsTask
Original file line number Diff line number Diff line change
Expand Up @@ -648,15 +648,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 @@ -761,124 +752,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 @@ -896,16 +775,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 @@ -1060,18 +929,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 @@ -1213,71 +1070,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
Loading

0 comments on commit f2eae40

Please sign in to comment.