@@ -232,6 +232,10 @@ type ValueTaskValueOptionBuilderBase() =
232232 : CancellableValueTaskValueOption < 'T > =
233233 taskOption
234234
235+ // member inline this.Source(taskOption: ValueTask<'T option>) : CancellableTaskOption<'T> =
236+ // taskOption.AsTask()
237+
238+
235239type ValueTaskValueOptionBuilder () =
236240
237241 inherit ValueTaskValueOptionBuilderBase()
@@ -351,6 +355,76 @@ type TaskOptionBuilder() =
351355 return ValueOption.toOption r
352356 }
353357
358+
359+ // type BackgroundTaskOptionBuilder() =
360+
361+ // inherit TaskOptionBuilderBase()
362+
363+ // static member RunDynamic(code: TaskOptionCode<'T, 'T>) : CancellableTaskOption<'T> =
364+ // // backgroundTask { .. } escapes to a background thread where necessary
365+ // // See spec of ConfigureAwait(false) at https://devblogs.microsoft.com/dotnet/configureawait-faq/
366+ // if
367+ // isNull SynchronizationContext.Current
368+ // && obj.ReferenceEquals(TaskScheduler.Current, TaskScheduler.Default)
369+ // then
370+ // TaskOptionBuilder.RunDynamic(code)
371+ // else
372+ // Task.Run<'T option>(fun () -> TaskOptionBuilder.RunDynamic(code))
373+
374+
375+ // //// Same as TaskBuilder.Run except the start is inside Task.Run if necessary
376+ // member inline _.Run(code: TaskOptionCode<'T, 'T>) : CancellableTaskOption<'T> =
377+ // if __useResumableCode then
378+ // __stateMachine<TaskOptionStateMachineData<'T>, CancellableTaskOption<'T>>
379+ // (MoveNextMethodImpl<_>(fun sm ->
380+ // //-- RESUMABLE CODE START
381+ // __resumeAt sm.ResumptionPoint
382+
383+ // try
384+ // let __stack_code_fin = code.Invoke(&sm)
385+
386+ // if
387+ // __stack_code_fin
388+ // && not sm.Data.IsTaskCompleted
389+ // then
390+ // sm.Data.MethodBuilder.SetResult(sm.Data.Result.Value)
391+ // with exn ->
392+ // sm.Data.MethodBuilder.SetException exn
393+ // //-- RESUMABLE CODE END
394+ // ))
395+ // (SetStateMachineMethodImpl<_>(fun sm state ->
396+ // sm.Data.MethodBuilder.SetStateMachine(state)
397+ // ))
398+ // (AfterCode<_, CancellableTaskOption<'T>>(fun sm ->
399+ // // backgroundTask { .. } escapes to a background thread where necessary
400+ // // See spec of ConfigureAwait(false) at https://devblogs.microsoft.com/dotnet/configureawait-faq/
401+ // if
402+ // isNull SynchronizationContext.Current
403+ // && obj.ReferenceEquals(TaskScheduler.Current, TaskScheduler.Default)
404+ // then
405+ // sm.Data.MethodBuilder <- AsyncTaskOptionMethodBuilder<'T>.Create()
406+ // sm.Data.MethodBuilder.Start(&sm)
407+ // sm.Data.MethodBuilder.Task
408+ // else
409+ // let sm = sm // copy contents of state machine so we can capture it
410+
411+ // Task.Run<'T option>(fun () ->
412+ // let mutable sm = sm // host local mutable copy of contents of state machine on this thread pool thread
413+ // sm.Data.MethodBuilder <- AsyncTaskOptionMethodBuilder<'T>.Create()
414+ // sm.Data.MethodBuilder.Start(&sm)
415+ // sm.Data.MethodBuilder.Task
416+ // )
417+ // ))
418+ // else
419+ // BackgroundTaskOptionBuilder.RunDynamic(code)
420+
421+ // [<AutoOpen>]
422+ // module TaskOptionBuilder =
423+
424+ // let taskOption = ValueTaskValueOptionBuilder()
425+ // let backgroundTaskOption = BackgroundTaskOptionBuilder()
426+
427+
354428[<AutoOpen>]
355429module TaskOptionCEExtensionsLowPriority =
356430 // Low priority extensions
@@ -552,3 +626,36 @@ module TaskOptionCEExtensionsHighPriority =
552626 this.Bind( task, ( fun v -> this.Return v))
553627
554628 member inline _.Source ( s : #seq<_> ) = s
629+
630+ // [<AutoOpen>]
631+ // module TaskOptionCEExtensionsMediumPriority =
632+
633+ // // Medium priority extensions
634+ // type TaskOptionBuilderBase with
635+
636+ // member inline this.Source(t: Task<'T>) : CancellableTaskOption<'T> =
637+ // t
638+ // |> Task.map Some
639+
640+ // member inline this.Source(t: Task) : CancellableTaskOption<unit> =
641+ // task {
642+ // do! t
643+ // return Some()
644+ // }
645+
646+ // member inline this.Source(t: ValueTask<'T>) : CancellableTaskOption<'T> =
647+ // t
648+ // |> Task.mapV Some
649+
650+ // member inline this.Source(t: ValueTask) : CancellableTaskOption<unit> =
651+ // task {
652+ // do! t
653+ // return Some()
654+ // }
655+
656+ // member inline this.Source(opt: Option<'T>) : CancellableTaskOption<'T> = Task.FromResult opt
657+
658+ // member inline this.Source(computation: Async<'T>) : CancellableTaskOption<'T> =
659+ // computation
660+ // |> Async.map Some
661+ // |> Async.StartImmediateAsTask
0 commit comments