ligo/lib_stdlib_lwt/lwt_exit.ml

35 lines
1.4 KiB
OCaml
Raw Normal View History

2016-09-08 21:13:10 +04:00
(**************************************************************************)
(* *)
2017-11-14 03:36:14 +04:00
(* Copyright (c) 2014 - 2017. *)
2016-09-08 21:13:10 +04:00
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
exception Exit
2016-09-08 21:13:10 +04:00
let termination_thread, exit_wakener = Lwt.wait ()
let exit x = Lwt.wakeup exit_wakener x; raise Exit
2016-09-08 21:13:10 +04:00
let () =
Lwt.async_exception_hook :=
(function
| Exit -> ()
| exn ->
2017-01-14 16:13:27 +04:00
let backtrace = Printexc.get_backtrace () in
Logging.Node.Main.fatal_error "@[<v 2>%a%a@]"
(fun ppf exn ->
Format.fprintf ppf
"@[Uncaught (asynchronous) exception (%d):@ %a@]"
(Unix.getpid ())
Error_monad.pp_exn exn)
exn
(fun ppf backtrace ->
if String.length backtrace <> 0 then
Format.fprintf ppf
"@,Backtrace:@, @[<h>%a@]"
Format.pp_print_text backtrace)
backtrace ;
Lwt.wakeup exit_wakener 1)