package lwt-exit

All checked builds pass
  1. Overview
  2. Docs
An opinionated clean-exit and signal-handling library for Lwt programs

Install

dune-project
 Dependency

Authors

Maintainers

Sources

lwt-exit-1.0.tar.gz
md5=f8f1c83d88d8955e055e0ccca11a3072
sha512=0ba5ef4495d402f5364af3f84e5378b04c9a1c5296a7f8bb84a0246a0bded1d5f4e3ab8e601056d7f96580eec78179d117fbd56670058460d0ae2e0990883ac2

Description

Added to opam-repository:

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.

Dependencies (5)

  1. ptime
  2. lwt
  3. base-unix
  4. dune >= "2.0"
  5. ocaml >= "4.08"

Dev Dependencies

None

Optional Dependencies

None

Used by

None

Conflicts

None

Build status

Results of building lwt-exit with each compiler on check.ci.ocaml.org, run of against opam-repository 7cdc698. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
1.0 (this version) good good good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure