Demystify truncating internals of F# async/task expressions

This commit is contained in:
Bartosz Sypytkowski
2020-01-05 17:02:03 +01:00
parent 1ca8f79a36
commit af40cc3bfa
8 changed files with 134 additions and 3 deletions

View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Ben.Demystifier\Ben.Demystifier.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Ply" Version="0.1.7" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,35 @@
// Learn more about F# at http://fsharp.org
open System
open System.Diagnostics
open System.Threading.Tasks
open FSharp.Control.Tasks.Builders
let call i = async {
do! Async.Sleep 1
if i = 10 then
failwith "BOOM!"
return i
}
let run count = async {
let calls = Array.init count call
for call in calls do
let! _ = call
()
return 0
}
let makeTheCall () = task {
let! x = run 20
return x
}
[<EntryPoint>]
let main argv =
try
let results = makeTheCall().GetAwaiter().GetResult()
printfn "%A" results
with e ->
printfn "%s" <| string (e.Demystify())
0 // return an integer exit code

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
class Program