Skip to content

Commit c5a4c05

Browse files
author
Jamil Maqdis Anton
committed
Move Async module from ExceptionsHandler.fs to its own file. Add awaitTasksWithExceptions to display inner exceptions that are usually wrapped in AggregateExceptions.
1 parent 97a4277 commit c5a4c05

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/Async.fs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace SqlStreamStore.FSharp
2+
3+
module Async =
4+
5+
open System.Threading.Tasks
6+
7+
let map f m = async.Bind(m, (f >> async.Return))
8+
9+
let awaitTaskWithInnerException (task: Task<'T>): Async<'T> =
10+
Async.FromContinuations(fun (suc, exn, _cln) ->
11+
task.ContinueWith(fun (t: Task<'T>) ->
12+
if t.IsFaulted
13+
then if t.Exception.InnerExceptions.Count = 1 then
14+
exn t.Exception.InnerExceptions.[0]
15+
else
16+
exn t.Exception
17+
elif t.IsCanceled
18+
then exn (TaskCanceledException())
19+
else suc t.Result)
20+
|> ignore)
21+
22+
let awaitTaskWithInnerException' (task: Task): Async<unit> =
23+
Async.FromContinuations(fun (suc, exn, _cln) ->
24+
task.ContinueWith(fun (t: Task) ->
25+
if t.IsFaulted
26+
then if t.Exception.InnerExceptions.Count = 1 then
27+
exn t.Exception.InnerExceptions.[0]
28+
else
29+
exn t.Exception
30+
elif t.IsCanceled
31+
then exn (TaskCanceledException())
32+
else suc ())
33+
|> ignore)

src/SqlStreamStore.FSharp.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15+
<Compile Include="Async.fs" />
1516
<Compile Include="ExceptionsHandler.fs" />
1617
<Compile Include="Types.fs" />
1718
<Compile Include="AppendRaw.fs" />

0 commit comments

Comments
 (0)