package async_kernel

  1. Overview
  2. Docs
Monadic concurrency library

Install

Dune Dependency

Authors

Maintainers

Sources

v0.17.0.tar.gz
sha256=01ced973dbc70535f692f38bed524ae82dba17e26e58791b2fbf0d647b160d2e

doc/async_kernel/Async_kernel/Invariant/index.html

Module Async_kernel.InvariantSource

include module type of Core.Invariant
Sourcetype nonrec 'a t = 'a -> unit
Sourcemodule type S = Base.Invariant.S
Sourcemodule type S1 = Base.Invariant.S1
Sourcemodule type S2 = Base.Invariant.S2
Sourcemodule type S3 = Base.Invariant.S3
Sourceval invariant : Lexing.position -> 'a -> ('a -> Base.Sexp.t) -> (unit -> unit) -> unit

invariant here t sexp_of_t f runs f (), and if f raises, wraps the exception in an Error.t that states "invariant failed" and includes both the exception raised by f, as well as sexp_of_t t. Idiomatic usage looks like:

  invariant [%here] t [%sexp_of: t] (fun () ->
    ... check t's invariants ... )

For polymorphic types:

  let invariant check_a t =
    Invariant.invariant [%here] t [%sexp_of: _ t] (fun () -> ... )

It's okay to use [%sexp_of: _ t] because the exceptions raised by check_a will show the parts that are opaque at top-level.

Sourceval check_field : 'a -> 'b t -> ('a, 'b) Base.Field.t -> unit

check_field is used when checking invariants using Fields.iter. It wraps an exception raised when checking a field with the field's name. Idiomatic usage looks like:

  type t =
    { foo : Foo.t;
      bar : Bar.t;
    }
  [@@deriving fields]

  let invariant t : unit =
    Invariant.invariant [%here] t [%sexp_of: t] (fun () ->
      let check f = Invariant.check_field t f in
      Fields.iter
        ~foo:(check Foo.invariant)
        ~bar:(check Bar.invariant))
  ;;
Sourcemodule Async : sig ... end
OCaml

Innovation. Community. Security.