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 @@ -483,14 +483,17 @@ module Task =
483483 /// <param name =" source " >The source task.</param >
484484 /// <returns >A successful resulting task.</returns >
485485 /// <remarks >The result is always a successful task, unless the mapping function itself throws an exception.</remarks >
486- let inline recover ( mapper : exn -> 'T ) ( source : Task < 'T >) : Task < 'T > =
487- #if ! NET45
486+ #if ! NET45
487+ let inline recover ( [<InlineIfLambda>] mapper : exn -> 'T ) ( source : Task < 'T >) : Task < 'T > =
488488 let source = nullArgCheck ( nameof source) source
489- #else
489+
490+ tryWith ( fun () -> source) ( mapper >> Task.FromResult)
491+ #else
492+ let inline recover ( mapper : exn -> 'T ) ( source : Task < 'T >) : Task < 'T > =
490493 raiseIfNull " source" source
491- #endif
492494
493495 tryWith ( fun () -> source) ( mapper >> result)
496+ #endif
494497
495498 /// <summary >Maps the exception of a faulted task to another exception.</summary >
496499 /// <param name =" mapper " >Mapping function from exception to exception.</param >
Original file line number Diff line number Diff line change @@ -391,7 +391,11 @@ module ValueTask =
391391 /// <returns >A successful resulting task.</returns >
392392 /// <remarks >The result is always a successful task, unless the mapping function itself throws an exception.</remarks >
393393 let inline recover ( [<InlineIfLambda>] mapper : exn -> 'T ) ( source : ValueTask < 'T >) : ValueTask < 'T > =
394+ #if NET5_ 0_ OR_ GREATER
395+ tryWith ( mapper >> ValueTask.FromResult) ( fun () -> source)
396+ #else
394397 tryWith ( mapper >> result) ( fun () -> source)
398+ #endif
395399
396400 /// <summary >Maps the exception of a faulted task to another exception.</summary >
397401 /// <param name =" mapper " >Mapping function from exception to exception.</param >
You can’t perform that action at this time.
0 commit comments