claro.middleware.observe
Generic middlewares to observe resolution results.
wrap-observe
(wrap-observe engine observer-fn)
(wrap-observe engine predicate observer-fn)
Middleware that will pass any Resolvable
that matches predicate
– as well as the resolved result – to observer-fn
.
For example, to check the result of a specific Person
record:
(def run-engine
(-> (engine/engine)
(wrap-observe
#(and (instance? Person %) (= (:id %) 1))
prn)))
If no predicate
is given, all Resolvable
values will be observed.
wrap-observe*
added in 0.2.20
(wrap-observe* engine observer-fn)
(wrap-observe* engine wrap-fn observer-fn)
Middleware that will pass the environment, the batch and the full resolution result (a map of resolvable to value) to the given function.
wrap-observe-batches
(wrap-observe-batches engine observer-fn)
(wrap-observe-batches engine predicate observer-fn)
Middleware that will pass the result of any batch matching predicate
to observer-fn
.
For example, to increase a total resolvable counter for Person
records:
(def run-engine
(-> (engine/engine)
(wrap-observe-batches
#(instance? Person (first %))
(fn [result]
(swap! counter + (count result))))))
If no predicate
is given, every batch will be observed.
wrap-observe-batches-by-class
(wrap-observe-batches-by-class engine classes-to-observe observer-fn)
Middleware that will pass the result of any batch of classes-to-observe
to observer-fn
.
For example, to increase a total resolvable counter for Person
records:
(def run-engine
(-> (engine/engine)
(wrap-observe-batches-by-class
[Person]
(fn [result]
(swap! counter + (count result))))))
wrap-observe-by-class
(wrap-observe-by-class engine classes-to-observe observer-fn)
Middleware that will pass any Resolvable
of one of the given classes-to-observe
– as well as the resolved result – to observer-fn
.
For example, to check the result of a specific Person
record:
(def run-engine
(-> (engine/engine)
(wrap-observe-classes [Person] prn)))
wrap-observe-duration
(wrap-observe-duration engine observer-fn)
(wrap-observe-duration engine predicate observer-fn)
Identical to wrap-observe-batches, except that observer-fn
is passed an additional argument representing the resolution duration in nanoseconds.