Skip to content

Commit ed5faae

Browse files
authored
Updates IcedTask to 0.5.0 and refactoring of Tasklike CEs (#200)
* Update IcedTasks to 0.4.0 * Update IcedTasks to 0.5.0 and refactor
1 parent 236ba80 commit ed5faae

File tree

14 files changed

+341
-754
lines changed

14 files changed

+341
-754
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"editor.inlayHints.enabled": "off",
33
"FSharp.enableAdaptiveLspServer": true,
4-
"FSharp.enableMSBuildProjectGraph": true
4+
"FSharp.enableMSBuildProjectGraph": true,
5+
"editor.formatOnSave": true
56
}

build/build.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77
<ItemGroup>
88

99
<Compile Include="build.fs" />
1010
</ItemGroup>
1111
<Import Project="..\.paket\Paket.Restore.targets" />
12-
</Project>
12+
</Project>

paket.dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ nuget Microsoft.NET.Test.Sdk
4747
nuget YoloDev.Expecto.TestSdk
4848
nuget Fable.Mocha
4949
nuget Fable.Core >= 4.0.0-theta-006
50-
nuget IcedTasks >= 0.3.0
50+
nuget IcedTasks >= 0.5.0
5151
framework: netstandard2.1, net7.0
5252
storage: none
5353
condition: netstandard2_1

paket.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,8 +1026,8 @@ NUGET
10261026
FSharp.Core (7.0)
10271027
Hopac (0.5.1)
10281028
FSharp.Core (>= 4.5.2)
1029-
IcedTasks (0.3)
1030-
FSharp.Core (>= 7.0) - restriction: || (== net7.0) (&& (== netstandard2.1) (>= net7.0))
1029+
IcedTasks (0.5)
1030+
FSharp.Core (>= 7.0)
10311031
Microsoft.Bcl.AsyncInterfaces (6.0)
10321032
Microsoft.CodeCoverage (17.4) - restriction: || (== net7.0) (&& (== netstandard2.1) (>= net462)) (&& (== netstandard2.1) (>= netcoreapp3.1))
10331033
Microsoft.NET.Test.Sdk (17.4)

src/FsToolkit.ErrorHandling.AsyncSeq/FsToolkit.ErrorHandling.AsyncSeq.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
5+
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
66
<LangVersion>preview</LangVersion>
77
<DebugType>portable</DebugType>
88
</PropertyGroup>

src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultCE.fs

Lines changed: 161 additions & 383 deletions
Large diffs are not rendered by default.

src/FsToolkit.ErrorHandling.IcedTasks/FsToolkit.ErrorHandling.IcedTasks.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFrameworks>net7.0</TargetFrameworks>
5+
<TargetFrameworks>netstandard2.1</TargetFrameworks>
66
<LangVersion>preview</LangVersion>
77
<DebugType>portable</DebugType>
88
<NoWarn>FS3511;FS3513</NoWarn>

src/FsToolkit.ErrorHandling.JobResult/FsToolkit.ErrorHandling.JobResult.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
5+
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
66
<DebugType>portable</DebugType>
77
</PropertyGroup>
88

src/FsToolkit.ErrorHandling.TaskResult/FsToolkit.ErrorHandling.TaskResult.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
5+
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
66
<!-- <TargetFrameworks>netstandard2.1</TargetFrameworks> -->
77
<DebugType>portable</DebugType>
88
<LangVersion>preview</LangVersion>

src/FsToolkit.ErrorHandling.TaskResult/TaskOptionCE.fs

Lines changed: 13 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -476,63 +476,6 @@ and TaskOptionResumptionDynamicInfo<'TOverall> =
476476

477477
and TaskOptionCode<'TOverall, 'T> = ResumableCode<TaskOptionStateMachineData<'TOverall>, 'T>
478478

479-
480-
module TaskOptionBuilderBase =
481-
482-
let rec WhileDynamic
483-
(
484-
sm: byref<TaskOptionStateMachine<_>>,
485-
condition: unit -> bool,
486-
body: TaskOptionCode<_, _>
487-
) : bool =
488-
if condition () then
489-
if body.Invoke(&sm) then
490-
if sm.Data.IsResultNone then
491-
// Set the result now to allow short-circuiting of the rest of the CE.
492-
// Run/RunDynamic will skip setting the result if it's already been set.
493-
// Combine/CombineDynamic will not continue if the result has been set.
494-
sm.Data.SetResult()
495-
true
496-
else
497-
WhileDynamic(&sm, condition, body)
498-
else
499-
let rf = sm.ResumptionDynamicInfo.ResumptionFunc
500-
501-
sm.ResumptionDynamicInfo.ResumptionFunc <-
502-
(TaskOptionResumptionFunc<_>(fun sm ->
503-
WhileBodyDynamicAux(&sm, condition, body, rf)
504-
))
505-
506-
false
507-
else
508-
true
509-
510-
and WhileBodyDynamicAux
511-
(
512-
sm: byref<TaskOptionStateMachine<_>>,
513-
condition: unit -> bool,
514-
body: TaskOptionCode<_, _>,
515-
rf: TaskOptionResumptionFunc<_>
516-
) : bool =
517-
if rf.Invoke(&sm) then
518-
if sm.Data.IsResultNone then
519-
// Set the result now to allow short-circuiting of the rest of the CE.
520-
// Run/RunDynamic will skip setting the result if it's already been set.
521-
// Combine/CombineDynamic will not continue if the result has been set.
522-
sm.Data.SetResult()
523-
true
524-
else
525-
WhileDynamic(&sm, condition, body)
526-
else
527-
let rf = sm.ResumptionDynamicInfo.ResumptionFunc
528-
529-
sm.ResumptionDynamicInfo.ResumptionFunc <-
530-
(TaskOptionResumptionFunc<_>(fun sm -> WhileBodyDynamicAux(&sm, condition, body, rf)
531-
))
532-
533-
false
534-
535-
536479
type TaskOptionBuilderBase() =
537480

538481
member inline _.Delay
@@ -554,39 +497,6 @@ type TaskOptionBuilderBase() =
554497
true
555498
)
556499

557-
static member inline CombineDynamic
558-
(
559-
sm: byref<TaskOptionStateMachine<_>>,
560-
task1: TaskOptionCode<'TOverall, unit>,
561-
task2: TaskOptionCode<'TOverall, 'T>
562-
) : bool =
563-
let shouldContinue = task1.Invoke(&sm)
564-
565-
if sm.Data.IsTaskCompleted then
566-
true
567-
elif shouldContinue then
568-
task2.Invoke(&sm)
569-
else
570-
let rec resume (mf: TaskOptionResumptionFunc<_>) =
571-
TaskOptionResumptionFunc<_>(fun sm ->
572-
let shouldContinue = mf.Invoke(&sm)
573-
574-
if sm.Data.IsTaskCompleted then
575-
true
576-
elif shouldContinue then
577-
task2.Invoke(&sm)
578-
else
579-
sm.ResumptionDynamicInfo.ResumptionFunc <-
580-
(resume (sm.ResumptionDynamicInfo.ResumptionFunc))
581-
582-
false
583-
)
584-
585-
sm.ResumptionDynamicInfo.ResumptionFunc <-
586-
(resume (sm.ResumptionDynamicInfo.ResumptionFunc))
587-
588-
false
589-
590500
/// Chains together a step with its following step.
591501
/// Note that this requires that the first step has no result.
592502
/// This prevents constructs like `task { return 1; return 2; }`.
@@ -596,20 +506,11 @@ type TaskOptionBuilderBase() =
596506
task2: TaskOptionCode<'TOverall, 'T>
597507
) : TaskOptionCode<'TOverall, 'T> =
598508

599-
TaskOptionCode<'TOverall, 'T>(fun sm ->
600-
if __useResumableCode then
601-
//-- RESUMABLE CODE START
602-
// NOTE: The code for code1 may contain await points! Resuming may branch directly
603-
// into this code!
604-
// printfn "Combine Called Before Invoke --> "
605-
let __stack_fin = task1.Invoke(&sm)
606-
// printfn "Combine Called After Invoke --> %A " sm.Data.MethodBuilder.Task.Status
607-
608-
if sm.Data.IsTaskCompleted then true
609-
elif __stack_fin then task2.Invoke(&sm)
610-
else false
611-
else
612-
TaskOptionBuilderBase.CombineDynamic(&sm, task1, task2)
509+
ResumableCode.Combine(
510+
task1,
511+
TaskOptionCode<'TOverall, 'T>(fun sm ->
512+
if sm.Data.IsResultNone then true else task2.Invoke(&sm)
513+
)
613514
)
614515

615516
/// Builds a step that executes the body while the condition predicate is true.
@@ -618,33 +519,17 @@ type TaskOptionBuilderBase() =
618519
[<InlineIfLambda>] condition: unit -> bool,
619520
body: TaskOptionCode<'TOverall, unit>
620521
) : TaskOptionCode<'TOverall, unit> =
621-
TaskOptionCode<'TOverall, unit>(fun sm ->
622-
if __useResumableCode then
623-
//-- RESUMABLE CODE START
624-
let mutable __stack_go = true
625-
626-
while __stack_go
627-
&& not sm.Data.IsResultNone
628-
&& condition () do
629-
// printfn "While -> %A" sm.Data.Result
630-
// NOTE: The body of the state machine code for 'while' may contain await points, so resuming
631-
// the code will branch directly into the expanded 'body', branching directly into the while loop
632-
let __stack_body_fin = body.Invoke(&sm)
633-
// printfn "While After Invoke --> %A" sm.Data.Result
634-
// If the body completed, we go back around the loop (__stack_go = true)
635-
// If the body yielded, we yield (__stack_go = false)
636-
__stack_go <- __stack_body_fin
522+
ResumableCode.While(
523+
condition,
524+
TaskOptionCode<_, _>(fun sm ->
525+
let __stack_body_fin = body.Invoke(&sm)
637526

638527
if sm.Data.IsResultNone then
639-
// Set the result now to allow short-circuiting of the rest of the CE.
640-
// Run/RunDynamic will skip setting the result if it's already been set.
641-
// Combine/CombineDynamic will not continue if the result has been set.
642528
sm.Data.SetResult()
643-
644-
__stack_go
645-
//-- RESUMABLE CODE END
646-
else
647-
TaskOptionBuilderBase.WhileDynamic(&sm, condition, body)
529+
false
530+
else
531+
__stack_body_fin
532+
)
648533
)
649534

650535

0 commit comments

Comments
 (0)