From 01648154d5f204230f2539ff2158201277c468e5 Mon Sep 17 00:00:00 2001 From: 1eyewonder Date: Tue, 17 Dec 2024 12:53:09 -0600 Subject: [PATCH] Reverted changes to CancellableTaskOption since it isn't implemented yet --- .../CancellableTaskOption.fs | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskOption.fs b/src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskOption.fs index 4b43cf24..13f3b9cd 100644 --- a/src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskOption.fs +++ b/src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskOption.fs @@ -232,6 +232,10 @@ type ValueTaskValueOptionBuilderBase() = : CancellableValueTaskValueOption<'T> = taskOption +// member inline this.Source(taskOption: ValueTask<'T option>) : CancellableTaskOption<'T> = +// taskOption.AsTask() + + type ValueTaskValueOptionBuilder() = inherit ValueTaskValueOptionBuilderBase() @@ -351,6 +355,76 @@ 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, 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) + +// [] +// module TaskOptionBuilder = + +// let taskOption = ValueTaskValueOptionBuilder() +// let backgroundTaskOption = BackgroundTaskOptionBuilder() + + [] module TaskOptionCEExtensionsLowPriority = // Low priority extensions @@ -552,3 +626,36 @@ module TaskOptionCEExtensionsHighPriority = this.Bind(task, (fun v -> this.Return v)) member inline _.Source(s: #seq<_>) = s + +// [] +// 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 = +// 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 = +// 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