Module 1-Incr.Observer
An observer lets one get the value of an incremental, either by asking directly for the value or installing an on-update handler to run when the incremental's value changes.
One first creates an observer using observe
. One must then call stabilize
before making any observations on that observer.
Doing let o = observe t
causes subsequent calls to stabilize
to maintain the value of t
, until either:
disallow_future_use o
is called, oro
is garbage collected ando
has no on-update handlers.
val sexp_of_t : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> 'a t -> Ppx_sexp_conv_lib.Sexp.t
include Core_kernel.Invariant.S1 with type 'a t := 'a t
val invariant : 'a Base__.Invariant_intf.inv -> 'a t Base__.Invariant_intf.inv
val observing : 'a t -> 'a incremental
val use_is_allowed : _ t -> bool
val value : 'a t -> 'a Core_kernel.Or_error.t
value t
returns the current value oft
, orError
ift
does not currently have a stable value. In particular,value t
will returnError
in the following situations:- in the middle of stabilization.
- if
stabilize
has not been called sincet
was created. - if
disallow_future_use t
has been called. - if
observing t
is invalid.
Rather than using
value
in a function that runs during stabilization, one should usemap
orbind
to express the dependence of an incremental computation on an incremental.
val value_exn : 'a t -> 'a
module Update : sig ... end
on_update_exn t ~f
callsf
after the current stabilization and after each subsequent stabilization in whicht
changes, untildisallow_future_use t
is called.f
will be called at most once per stabilization. Here is a state diagram for the allowable sequences ofUpdate.t
's that can be supplied to a particularf
:
val on_update_exn : 'a t -> f:('a Update.t -> unit) -> unit
val disallow_future_use : _ t -> unit
disallow_future_use t
causes all future attempts to uset
to fail andon_update_exn
handlers added tot
to never run again. It also causes incremental to treatt
as unobserved, and thusstabilize
will not maintain the value oft
or any oft
's descendants that are needed only to maintaint
.disallow_future_use
raises if called during stabilization.