File tree Expand file tree Collapse file tree
src/FSharpPlus/Extensions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -348,17 +348,25 @@ module Task =
348348 try body ()
349349 with
350350 | _ ->
351- compensation ()
352- reraise ()
351+ try
352+ compensation ()
353+ reraise ()
354+ with e -> Task.FromException< 'T> e
353355 if task.IsCompleted then
354356 let res =
355- try
356- task.GetAwaiter() .GetResult ()
357+ try Ok ( task.GetAwaiter() .GetResult ())
357358 with _ ->
359+ try
360+ compensation ()
361+ reraise ()
362+ with e -> Error e
363+ match res with
364+ | Error e -> Task.FromException< 'T> e
365+ | Ok v ->
366+ try
358367 compensation ()
359- reraise ()
360- compensation ()
361- result res
368+ Task.FromResult v
369+ with e -> Task.FromException< 'T> e
362370 else
363371 task.ContinueWith( fun ( x : Task < 'T >) -> tryFinally ( fun () -> x) compensation) .Unwrap ()
364372
Original file line number Diff line number Diff line change @@ -323,17 +323,25 @@ module ValueTask =
323323 try body ()
324324 with
325325 | _ ->
326- compensation ()
327- reraise ()
326+ try
327+ compensation ()
328+ reraise ()
329+ with e -> ValueTask.FromException< 'T> e
328330 if task.IsCompleted then
329331 let res =
330- try
331- task.GetAwaiter() .GetResult ()
332+ try Ok ( task.GetAwaiter() .GetResult ())
332333 with _ ->
334+ try
335+ compensation ()
336+ reraise ()
337+ with e -> Error e
338+ match res with
339+ | Error e -> ValueTask.FromException< 'T> e
340+ | Ok v ->
341+ try
333342 compensation ()
334- reraise ()
335- compensation ()
336- result res
343+ ValueTask.FromResult v
344+ with e -> ValueTask.FromException< 'T> e
337345 else
338346 task.AsTask() .ContinueWith( fun ( x : Task < 'T >) -> Task.tryFinally compensation ( fun () -> x)) .Unwrap () |> ValueTask< 'T>
339347
You can’t perform that action at this time.
0 commit comments