package bap-primus-greedy-scheduler
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9c126781385d2fa9b8edab22e62b25c70bf2f99f6ec78abb7e5e36d63cfa4174
md5=5abd9b3628b43f797326034f31ca574f
doc/bap-plugin-primus_greedy/Primus_greedy_main/Greedy/argument-1-Machine/Observation/index.html
Module Machine.Observation
Observations interface.
val observe : 'a Bap_primus.Std.Primus.observation -> ('a -> unit t) -> unit tobserve 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 tsubscribe obs handler creates a cancelable subscription to the observation obs.
Returns a subscription handler that could be used to cancel the subscription.
val cancel : Bap_primus.Std.Primus.subscription -> unit tcancel 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 twatch 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.
val make : 'a Bap_primus.Std.Primus.statement -> 'a -> unit tmake observation event make an observation of the given event.
val post :
'a Bap_primus.Std.Primus.statement ->
f:(('a -> unit t) -> unit t) ->
unit tpost observation k makes observation if necessary.
The continuation 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.
The function 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.