Skip to content

Commit ef4bc6e

Browse files
Wrap onReceived in an async computional expression. (#12)
Co-authored-by: Emil Klasson <emil.klasson@insurello.se>
1 parent 6996221 commit ef4bc6e

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/Insurello.RabbitMqClient/MqClient.fs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -558,28 +558,21 @@ module MqClient =
558558
fun logError onReceived ->
559559
{ OnReceived =
560560
fun message ->
561-
onReceived message
562-
|> Async.Catch
563-
|> Async.map (function
564-
| Choice1Of2 _ -> ()
565-
| Choice2Of2 err ->
566-
logError (err, (sprintf "💥 Unexpected error. %A\nShutting down" err), ())
567-
568-
exit 2)
561+
// Somthing weird happens with exception handeling when not
562+
// using Async computational expression. Some exepctions are
563+
// silenty swollowed and never bubbles up.
564+
async {
565+
try
566+
do! onReceived message
567+
with exn ->
568+
logError (exn, (sprintf "💥 Unexpected error. %A\nShutting down" exn), ())
569+
exit 2
570+
}
569571

570572
OnRegistered = fun _ -> Async.singleton ()
571573

572-
OnUnregistered =
573-
fun _ ->
574-
failwith "Got OnUnregistered event"
575-
Async.singleton ()
574+
OnUnregistered = fun _ -> failwith "Got OnUnregistered event"
576575

577-
OnConsumerCancelled =
578-
fun _ ->
579-
failwith "Got OnConsumerCancelled event"
580-
Async.singleton ()
576+
OnConsumerCancelled = fun _ -> failwith "Got OnConsumerCancelled event"
581577

582-
OnShutdown =
583-
fun _ ->
584-
failwith "Got OnShutdown event"
585-
Async.singleton () }
578+
OnShutdown = fun _ -> failwith "Got OnShutdown event" }

0 commit comments

Comments
 (0)