package lwt-exit
Install
Dune Dependency
Authors
Maintainers
Sources
md5=f8f1c83d88d8955e055e0ccca11a3072
sha512=0ba5ef4495d402f5364af3f84e5378b04c9a1c5296a7f8bb84a0246a0bded1d5f4e3ab8e601056d7f96580eec78179d117fbd56670058460d0ae2e0990883ac2
Description
Published: 07 Dec 2020
README
Lwt-exit
Lwt-exit is a somewhat opinionated library for handling signals and clean exit in programs that use Lwt for concurrency.
Installation
Lwt-exit is available through opam:
opam install lwt-exit
Use
There are two sides to Lwt-exit: the cleaning up of resources when the program exits and the handling of signals whilst the program is running. These two sides are somewhat indepenedet, but note that signal handling can trigger an exit which triggers the cleaning up of resources.
You can set up resource clean-up as follows:
let output_socket = .. (* allocate resource *) in
let _ =
Lwt_exit.register_clean_up_callback
~loc:__LOC__ (* used if needed for error reporting *)
(fun exit_code ->
.. (* clean-up resource *)
)
in
You can trigger an exit from within your own program. This is similar to using Stdlib.exit
but it will ensure the clean-up callbacks are executed.
match message with
| `Payload m -> process m
| `Stop -> Lwt_exit.exit_and_raise 0 (* exit-code 0 *)
| `Abort -> Lwt_exit.exit_and_raise 1 (* exit-code 1 *)
In addition, you can set up signal handlers which may trigger exits on their own.
let signal_setup = make_signal_setup ~soft:[..] ~hard:[]
Finally, you must wrap the main promise of your program:
let () = Lwt_main.run @@ Lwt_exit.wrap_and_exit ~signal_setup @@ ..
Check the documentation inline in the mli (src/lwt_exit.mli
) or online for more information, advanced uses and additional examples.
Historical notes
The previous versions of Lwt-exit were developped as part of the Tezos project and is now used as an external depenedency.
Dev Dependencies
None
Used by (25)
- octez-node
-
octez-protocol-017-PtNairob-libs
< "20.1"
- octez-protocol-018-Proxford-libs
- octez-protocol-019-PtParisB-libs
- octez-protocol-020-PsParisC-libs
- octez-protocol-alpha-libs
- octez-proxy-server
- octez-rpc-process
- octez-shell-libs
-
tezos-baking-008-PtEdo2Zk
>= "9.0"
- tezos-baking-009-PsFLoren
- tezos-baking-010-PtGRANAD
- tezos-baking-011-PtHangz2
- tezos-baking-012-Psithaca
- tezos-baking-013-PtJakart
- tezos-baking-014-PtKathma
- tezos-baking-015-PtLimaPt
- tezos-baking-016-PtMumbai
- tezos-baking-017-PtNairob
-
tezos-baking-alpha
>= "9.0"
-
tezos-client-base-unix
>= "9.0"
-
tezos-node
>= "13.0"
-
tezos-protocol-updater
>= "9.0"
- tezos-proxy-server
-
tezos-shell
>= "13.0"
Conflicts
None