module type Value
observe obs on_observation subscribes to the given observation
obs. Every time the observation
obs is made a function
on_observation is called. The function can perform arbitrary computations in the machine monad, e.g., make its own computations, or access other components via their interfaces.
val subscribe : 'a Bap_primus.Std.Primus.observation -> ( 'a -> unit t ) -> Bap_primus.Std.Primus.subscription t
subscribe obs handler creates a cancelable subscription to the observation
Returns a subscription handler that could be used to cancel the subscription.
cancel sub cancels the given subscription.
An observation that was registered under this subscription won't be called anymore.
val watch : Bap_primus.Std.Primus.Observation.provider -> ( Core_kernel.Sexp.t -> unit t ) -> unit t
watch prov data watches for the data provider.
This function is the same as
observe except that it uses the provider to access the observation and gets the observation in the sexp-serialized form.
make observation event make an
observation of the given
post observation k makes observation if necessary.
k is a function that is called only when the given statement has subscribers.
Use this function to skip creating an observation if nobody is interested in it. This is useful, when the observation has some cost to construct, so when there no subscribers no machine cycles will be lost.
k receives a
provide function that could be used to provide observation once it is ready, e.g.,
Observation.post big_thing ~f:(fun provide -> some_costly_function1 >>= fun x -> some_costly_function2 >>= fun y -> some_costly_function3 >>= fun z -> provide (x,y,z))
Note: even for observations that are tuples this function is efficient as sometimes the compiler can optimize the closure creation or the closure itself might be smaller than the created observation.