Module Expert.Node
val sexp_of_t : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> ('w -> Ppx_sexp_conv_lib.Sexp.t) -> ('a, 'w) t -> Ppx_sexp_conv_lib.Sexp.t
val create : 'w State.t -> ?on_observability_change:(is_now_observable:bool -> unit) -> (unit -> 'a) -> ('a, 'w) t
let t = create ?on_observability_change callback
creates a new expert node.on_observability_change
, if given, is called whenever the node becomes observable or unobservable (with alternating value foris_now_observable
, starting attrue
the first time the node becomes observable). This callback could run multiple times per stabilization. It should not change the incremental graph.callback
is called if any dependency oft
has changed since it was last called, or if the set of dependencies has changed. The callback will only run when all the dependencies are up-to-date, and inside the callback, you can safely callDependency.value
on your dependencies, as well as call all the functions below on the parent nodes. Any behavior that works on all incremental nodes (cutoff, invalidation, debug info etc) also work ont
.
val watch : ('a, 'w) t -> ('a, 'w) incremental
watch t
allows you to plugt
in the rest of the incremental graph, but it's also useful to set a cutoff function, debug info etc.
val make_stale : (_, _) t -> unit
Calling
make_stale t
ensures that incremental will recomputet
before anyone reads its value.t
may not fire though, if it never becomes necessary. This is intended to be called only from a child oft
. Along with a well chosen cutoff function, it allows to choose which parents should fire.
val invalidate : (_, _) t -> unit
invalidate t
makest
invalid, as if its surrounding bind had changed. This is intended to be called only from a child oft
.
val add_dependency : (_, 'w) t -> (_, 'w) Dependency.t -> unit
add_dependency t dep
makest
depend on the child incremental in thedep
. Ifdep
is already used to link the child incremental to another parent, an exception is raised.This is intended to be called either outside of stabilization, or right after creating
t
, or from a child oft
(and in that case, as a consequencet
must be necessary).The
on_change
callback ofdep
will be fired whent
becomes observable, or immediately, or whenever the child changes as long ast
is observable. When this function is called due to observability changes, the callback may fire several times in the same stabilization, so it should be idempotent. The callback must not change the incremental graph, particularly not the dependencies oft
.All the
on_change
callbacks are guaranteed to be run before the callback ofcreate
is run.
val remove_dependency : (_, 'w) t -> (_, 'w) Dependency.t -> unit
remove_dependency t dep
can only be called from a child oft
.