Skip to content

Commit 9038995

Browse files
authored
Cleanup for asyncenumerable generation (#53)
* Cleanup For/IAsyncEnumerable code generation * Add examples project and ILSpySamples for demonstration of task generation * Future proof FSharp.Core reference * cleanups
1 parent 085910d commit 9038995

File tree

16 files changed

+188
-133
lines changed

16 files changed

+188
-133
lines changed

IcedTasks.sln

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "IcedTasks.Tests.NS20", "tes
2323
EndProject
2424
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "IcedTasks.Tests.NS21", "tests\IcedTasks.Tests.NS21\IcedTasks.Tests.NS21.fsproj", "{04D5314E-2B8F-442B-9983-DCD12CC43448}"
2525
EndProject
26+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{B36A84DF-456D-A817-6EDD-3EC3E7F6E11F}"
27+
EndProject
28+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ILSpySamples", "examples\ILSpySamples\ILSpySamples.fsproj", "{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}"
29+
EndProject
2630
Global
2731
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2832
Debug|Any CPU = Debug|Any CPU
@@ -32,9 +36,6 @@ Global
3236
Release|x64 = Release|x64
3337
Release|x86 = Release|x86
3438
EndGlobalSection
35-
GlobalSection(SolutionProperties) = preSolution
36-
HideSolutionNode = FALSE
37-
EndGlobalSection
3839
GlobalSection(ProjectConfigurationPlatforms) = postSolution
3940
{5D30E174-2538-47AC-8443-318C8C5DC2C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4041
{5D30E174-2538-47AC-8443-318C8C5DC2C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
@@ -72,54 +73,6 @@ Global
7273
{40D2259D-991D-44C4-B45D-C88CE0710C23}.Release|x64.Build.0 = Release|Any CPU
7374
{40D2259D-991D-44C4-B45D-C88CE0710C23}.Release|x86.ActiveCfg = Release|Any CPU
7475
{40D2259D-991D-44C4-B45D-C88CE0710C23}.Release|x86.Build.0 = Release|Any CPU
75-
{A7F8AEA0-030B-415E-AD31-749FFFB46F9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
76-
{A7F8AEA0-030B-415E-AD31-749FFFB46F9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
77-
{A7F8AEA0-030B-415E-AD31-749FFFB46F9D}.Debug|x64.ActiveCfg = Debug|Any CPU
78-
{A7F8AEA0-030B-415E-AD31-749FFFB46F9D}.Debug|x64.Build.0 = Debug|Any CPU
79-
{A7F8AEA0-030B-415E-AD31-749FFFB46F9D}.Debug|x86.ActiveCfg = Debug|Any CPU
80-
{A7F8AEA0-030B-415E-AD31-749FFFB46F9D}.Debug|x86.Build.0 = Debug|Any CPU
81-
{A7F8AEA0-030B-415E-AD31-749FFFB46F9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
82-
{A7F8AEA0-030B-415E-AD31-749FFFB46F9D}.Release|Any CPU.Build.0 = Release|Any CPU
83-
{A7F8AEA0-030B-415E-AD31-749FFFB46F9D}.Release|x64.ActiveCfg = Release|Any CPU
84-
{A7F8AEA0-030B-415E-AD31-749FFFB46F9D}.Release|x64.Build.0 = Release|Any CPU
85-
{A7F8AEA0-030B-415E-AD31-749FFFB46F9D}.Release|x86.ActiveCfg = Release|Any CPU
86-
{A7F8AEA0-030B-415E-AD31-749FFFB46F9D}.Release|x86.Build.0 = Release|Any CPU
87-
{A1AE63B4-36B5-4445-ABBB-5991AB6E9F7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
88-
{A1AE63B4-36B5-4445-ABBB-5991AB6E9F7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
89-
{A1AE63B4-36B5-4445-ABBB-5991AB6E9F7F}.Debug|x64.ActiveCfg = Debug|Any CPU
90-
{A1AE63B4-36B5-4445-ABBB-5991AB6E9F7F}.Debug|x64.Build.0 = Debug|Any CPU
91-
{A1AE63B4-36B5-4445-ABBB-5991AB6E9F7F}.Debug|x86.ActiveCfg = Debug|Any CPU
92-
{A1AE63B4-36B5-4445-ABBB-5991AB6E9F7F}.Debug|x86.Build.0 = Debug|Any CPU
93-
{A1AE63B4-36B5-4445-ABBB-5991AB6E9F7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
94-
{A1AE63B4-36B5-4445-ABBB-5991AB6E9F7F}.Release|Any CPU.Build.0 = Release|Any CPU
95-
{A1AE63B4-36B5-4445-ABBB-5991AB6E9F7F}.Release|x64.ActiveCfg = Release|Any CPU
96-
{A1AE63B4-36B5-4445-ABBB-5991AB6E9F7F}.Release|x64.Build.0 = Release|Any CPU
97-
{A1AE63B4-36B5-4445-ABBB-5991AB6E9F7F}.Release|x86.ActiveCfg = Release|Any CPU
98-
{A1AE63B4-36B5-4445-ABBB-5991AB6E9F7F}.Release|x86.Build.0 = Release|Any CPU
99-
{3D0BC2AF-F28D-4A5D-8D69-BBD33696DB42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
100-
{3D0BC2AF-F28D-4A5D-8D69-BBD33696DB42}.Debug|Any CPU.Build.0 = Debug|Any CPU
101-
{3D0BC2AF-F28D-4A5D-8D69-BBD33696DB42}.Debug|x64.ActiveCfg = Debug|Any CPU
102-
{3D0BC2AF-F28D-4A5D-8D69-BBD33696DB42}.Debug|x64.Build.0 = Debug|Any CPU
103-
{3D0BC2AF-F28D-4A5D-8D69-BBD33696DB42}.Debug|x86.ActiveCfg = Debug|Any CPU
104-
{3D0BC2AF-F28D-4A5D-8D69-BBD33696DB42}.Debug|x86.Build.0 = Debug|Any CPU
105-
{3D0BC2AF-F28D-4A5D-8D69-BBD33696DB42}.Release|Any CPU.ActiveCfg = Release|Any CPU
106-
{3D0BC2AF-F28D-4A5D-8D69-BBD33696DB42}.Release|Any CPU.Build.0 = Release|Any CPU
107-
{3D0BC2AF-F28D-4A5D-8D69-BBD33696DB42}.Release|x64.ActiveCfg = Release|Any CPU
108-
{3D0BC2AF-F28D-4A5D-8D69-BBD33696DB42}.Release|x64.Build.0 = Release|Any CPU
109-
{3D0BC2AF-F28D-4A5D-8D69-BBD33696DB42}.Release|x86.ActiveCfg = Release|Any CPU
110-
{3D0BC2AF-F28D-4A5D-8D69-BBD33696DB42}.Release|x86.Build.0 = Release|Any CPU
111-
{942D0FD2-BD36-488A-86D8-0141CBAA62DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
112-
{942D0FD2-BD36-488A-86D8-0141CBAA62DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
113-
{942D0FD2-BD36-488A-86D8-0141CBAA62DF}.Debug|x64.ActiveCfg = Debug|Any CPU
114-
{942D0FD2-BD36-488A-86D8-0141CBAA62DF}.Debug|x64.Build.0 = Debug|Any CPU
115-
{942D0FD2-BD36-488A-86D8-0141CBAA62DF}.Debug|x86.ActiveCfg = Debug|Any CPU
116-
{942D0FD2-BD36-488A-86D8-0141CBAA62DF}.Debug|x86.Build.0 = Debug|Any CPU
117-
{942D0FD2-BD36-488A-86D8-0141CBAA62DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
118-
{942D0FD2-BD36-488A-86D8-0141CBAA62DF}.Release|Any CPU.Build.0 = Release|Any CPU
119-
{942D0FD2-BD36-488A-86D8-0141CBAA62DF}.Release|x64.ActiveCfg = Release|Any CPU
120-
{942D0FD2-BD36-488A-86D8-0141CBAA62DF}.Release|x64.Build.0 = Release|Any CPU
121-
{942D0FD2-BD36-488A-86D8-0141CBAA62DF}.Release|x86.ActiveCfg = Release|Any CPU
122-
{942D0FD2-BD36-488A-86D8-0141CBAA62DF}.Release|x86.Build.0 = Release|Any CPU
12376
{D6F24191-0EA5-4591-908E-C7AB20BF3016}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12477
{D6F24191-0EA5-4591-908E-C7AB20BF3016}.Debug|Any CPU.Build.0 = Debug|Any CPU
12578
{D6F24191-0EA5-4591-908E-C7AB20BF3016}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -168,6 +121,21 @@ Global
168121
{04D5314E-2B8F-442B-9983-DCD12CC43448}.Release|x64.Build.0 = Release|Any CPU
169122
{04D5314E-2B8F-442B-9983-DCD12CC43448}.Release|x86.ActiveCfg = Release|Any CPU
170123
{04D5314E-2B8F-442B-9983-DCD12CC43448}.Release|x86.Build.0 = Release|Any CPU
124+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
125+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}.Debug|Any CPU.Build.0 = Debug|Any CPU
126+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}.Debug|x64.ActiveCfg = Debug|Any CPU
127+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}.Debug|x64.Build.0 = Debug|Any CPU
128+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}.Debug|x86.ActiveCfg = Debug|Any CPU
129+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}.Debug|x86.Build.0 = Debug|Any CPU
130+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}.Release|Any CPU.ActiveCfg = Release|Any CPU
131+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}.Release|Any CPU.Build.0 = Release|Any CPU
132+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}.Release|x64.ActiveCfg = Release|Any CPU
133+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}.Release|x64.Build.0 = Release|Any CPU
134+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}.Release|x86.ActiveCfg = Release|Any CPU
135+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02}.Release|x86.Build.0 = Release|Any CPU
136+
EndGlobalSection
137+
GlobalSection(SolutionProperties) = preSolution
138+
HideSolutionNode = FALSE
171139
EndGlobalSection
172140
GlobalSection(NestedProjects) = preSolution
173141
{5D30E174-2538-47AC-8443-318C8C5DC2C9} = {C397A34C-84F1-49E7-AEBC-2F9F2B196216}
@@ -176,5 +144,6 @@ Global
176144
{96680B92-6CB6-4DE4-9112-32C70B2A7A60} = {ADB30C52-C398-49B6-B757-E8A447890BD0}
177145
{446B1378-DDC2-47CD-A6F2-C10F946B7E12} = {ACBEE43C-7A88-4FB1-9B06-DB064D22B29F}
178146
{04D5314E-2B8F-442B-9983-DCD12CC43448} = {ACBEE43C-7A88-4FB1-9B06-DB064D22B29F}
147+
{130D8BDE-DAB6-4B12-925D-A9CFEC9F8B02} = {B36A84DF-456D-A817-6EDD-3EC3E7F6E11F}
179148
EndGlobalSection
180149
EndGlobal
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
<IsPackable>false</IsPackable>
8-
</PropertyGroup>
9-
10-
11-
</Project>
2+
<PropertyGroup>
3+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
</Project>

benchmarks/FSharpBenchmarks/benchmarks.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
</ItemGroup>
2424
<ItemGroup>
2525
<PackageReference Include="BenchmarkDotNet" />
26-
<PackageReference Include="Ply"/>
26+
<PackageReference Include="Ply" />
2727
</ItemGroup>
28-
</Project>
28+
</Project>

build/build.fsproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<Project Sdk="Microsoft.NET.Sdk">
32
<PropertyGroup>
43
<OutputType>Exe</OutputType>
@@ -11,7 +10,6 @@
1110
<Compile Include="Changelog.fs" />
1211
<Compile Include="build.fs" />
1312
</ItemGroup>
14-
1513
<ItemGroup>
1614
<PackageReference Include="Argu" />
1715
<PackageReference Include="Fake.IO.FileSystem" />
@@ -25,7 +23,6 @@
2523
<PackageReference Include="Fake.Api.GitHub" />
2624
<PackageReference Include="Fake.BuildServer.GitHubActions" />
2725
<PackageReference Include="Octokit" />
28-
<PackageReference Include="MSBuild.StructuredLogger"/>
29-
26+
<PackageReference Include="MSBuild.StructuredLogger" />
3027
</ItemGroup>
31-
</Project>
28+
</Project>

examples/Directory.Build.props

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project>
2+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
3+
<ItemGroup>
4+
<!-- Dotnet Watch to know about this file -->
5+
<Watch Include="$(MSBuildThisFileFullPath)"/>
6+
</ItemGroup>
7+
<PropertyGroup>
8+
<GenerateDocumentationFile>false</GenerateDocumentationFile>
9+
<IsPackable>false</IsPackable>
10+
<IsTestProject>false</IsTestProject>
11+
</PropertyGroup>
12+
13+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net9.0</TargetFramework>
4+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<Compile Include="Library.fs" />
8+
</ItemGroup>
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\src\IcedTasks\IcedTasks.fsproj" />
11+
</ItemGroup>
12+
</Project>

examples/ILSpySamples/Library.fs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
namespace ILSpySamples
2+
3+
open System.Threading.Tasks
4+
open System.Collections.Generic
5+
6+
7+
module Task =
8+
9+
let forLoopEnumerable (x: IEnumerable<_>) =
10+
task {
11+
for i in x do
12+
do! Task.Yield()
13+
printfn "%A" i
14+
}
15+
16+
module IcedTasks =
17+
open IcedTasks
18+
19+
module Task =
20+
open IcedTasks.Polyfill.Task
21+
22+
let forLoopEnumerable (x: IEnumerable<_>) =
23+
task {
24+
for i in x do
25+
do! Task.Yield()
26+
printfn "%A" i
27+
}
28+
29+
30+
let forLoopAsyncEnmerable (x: IAsyncEnumerable<_>) =
31+
task {
32+
for i in x do
33+
do! Task.Yield()
34+
printfn "%A" i
35+
}
36+
37+
let tryFinally () =
38+
task {
39+
try
40+
do! Task.Yield()
41+
finally
42+
printfn "finally2"
43+
}
44+
45+
46+
module CT =
47+
open IcedTasks.Polyfill.Task
48+
49+
let forLoopEnumerable (x: IEnumerable<_>) =
50+
cancellableTask {
51+
for i in x do
52+
do! Task.Yield()
53+
printfn "%A" i
54+
}
55+
56+
let forLoopAsyncEnmerable (x: IAsyncEnumerable<_>) =
57+
cancellableTask {
58+
for i in x do
59+
do! Task.Yield()
60+
printfn "%A" i
61+
}

examples/ILSpySamples/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ILSpy Samples
2+
3+
Playground for seeing what ILSpy says about our Task generation code.

src/IcedTasks/AsyncEx.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type AsyncEx =
3939
// the task may not have a cancellation token at all).
4040
onError e
4141

42-
Async.FromContinuations(fun (onNext, onError, onCancel) ->
42+
Async.FromContinuations(fun (onNext, onError, _onCancel) ->
4343
if Awaiter.IsCompleted awaiter then
4444
handleFinished (onNext, onError, awaiter)
4545
else

src/IcedTasks/CancellableTask.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ module CancellableTasks =
160160
let left = left ct
161161
let right = right ct
162162

163-
(this.Bind(
163+
this.Bind(
164164
left,
165165
fun leftR ->
166166
this.BindReturn(right, (fun rightR -> struct (leftR, rightR)))
167-
))
167+
)
168168
)
169169
)
170170
)
@@ -180,11 +180,11 @@ module CancellableTasks =
180180
fun ct ->
181181
let right = right ct
182182

183-
(this.Bind(
183+
this.Bind(
184184
left,
185185
fun leftR ->
186186
this.BindReturn(right, (fun rightR -> struct (leftR, rightR)))
187-
))
187+
)
188188
)
189189
)
190190
)
@@ -201,11 +201,11 @@ module CancellableTasks =
201201
fun ct ->
202202
let left = left ct
203203

204-
(this.Bind(
204+
this.Bind(
205205
left,
206206
fun leftR ->
207207
this.BindReturn(right, (fun rightR -> struct (leftR, rightR)))
208-
))
208+
)
209209
)
210210
)
211211
)

0 commit comments

Comments
 (0)