swlaschin / DomainModelingMadeFunctional

Extended code samples related to the book "Domain Modeling Made Functional". Buy the book here: https://pragprog.com/book/swdddf/domain-modeling-made-functional or here https://fsharpforfunandprofit.com/books/
Apache License 2.0
438 stars 84 forks source link

AsyncResult.catch don't work as expected #8

Closed AbrahamAlcaina closed 3 years ago

AbrahamAlcaina commented 5 years ago

Hello first, a really good book 👍 congrats. Here my doubt. I try to capture an exception in asyncResult with AsyncResult.catch but It doesn't work as expected. Here my tests:

Async example:

[<Fact>]
let asyncExceptionTest() = 
  let r = async {
              failwith "Ohh nooo!!!"
              return "ok"
            }
          |> Async.Catch
          |> Async.RunSynchronously
  match r with 
  | Choice1Of2 a -> printfn "ok --> %A" a        
  | Choice2Of2 e -> printfn "error -->%A" e

This example works well. It captures the exception. Now the same example with asyncResult.

[<Fact>]
let asyncResultTest() = 
  let r = asyncResult {
              failwith "Ohh nooo!!!"
              return "ok"
            }
          |> AsyncResult.catch ( fun ex -> printfn "%A" ex; ex)
          |> Async.RunSynchronously
  match r with 
  | Ok a -> printfn "ok --> %A" a        
  | Result.Error e -> printfn "error -->%A" e    

Here the code catch didn't catch the exception. Any ideas why?

allentiak commented 3 years ago

Just curious... Is this one fixed by #10?

AbrahamAlcaina commented 3 years ago

Just curious... Is this one fixed by #10?

Nop

allentiak commented 3 years ago

@AbrahamAlcaina Thanks for your reply :-)

swlaschin commented 3 years ago

Sorry for the delay. I finally got round to fixing this! Fixed in fcfe97f06308b6b8d1d7af97761874cf55ac4894