(wrap-cached f)adds a caching layer to the procedure
(-> ((wrap-cached (fn [inst args] (Thread/sleep 1000000))) {:result (promise) :cached true :cache (state/update (state/cache {}) assoc-in ["hello" :1 []] {:result (atom {:success true :value 42}) :runtime (atom {:ended 0})}) :name "hello" :id :1} []) deref) => {:success true, :value 42, :cached 0}
adds a caching layer to the procedure
(-> ((wrap-cached (fn [inst args] (Thread/sleep 1000000)))
{:result (promise)
:cached true
:cache (state/update (state/cache {})
assoc-in ["hello" :1 []]
{:result (atom {:success true :value 42})
:runtime (atom {:ended 0})})
:name "hello"
:id :1}
[])
deref)
=> {:success true, :value 42, :cached 0}(wrap-callback f)enables a callback to be added to the procedure for side effects
((procedure {:name "callback" :id :2 :handler (fn [] :FAST) :callback (fn [x] (println x))} []))
enables a callback to be added to the procedure for side effects
((procedure {:name "callback"
:id :2
:handler (fn [] :FAST)
:callback (fn [x] (println x))}
[]))(wrap-id f)creates an id for the instance
((wrap-id (fn [inst args] (:id inst))) {:id-fn (constantly :hello)} []) => :hello
creates an id for the instance
((wrap-id (fn [inst args] (:id inst)))
{:id-fn (constantly :hello)}
[])
=> :hello(wrap-instance f)enables the entire instance to be passed in
((wrap-instance (fn [_ args] (first args))) {:arglist [:instance]} [nil]) => {:arglist [:instance]}
((wrap-instance (fn [_ [inst]] (:params inst))) {:arglist [:instance] :params :b} [nil]) => :b
enables the entire instance to be passed in
((wrap-instance (fn [_ args] (first args)))
{:arglist [:instance]}
[nil])
=> {:arglist [:instance]}
((wrap-instance (fn [_ [inst]] (:params inst)))
{:arglist [:instance] :params :b}
[nil])
=> :b(wrap-interrupt f)interrupts the existing procedure
(do ((procedure {:name "hello" :id :1 :handler (fn [] (Thread/sleep 1000000000))} [])) (Thread/sleep 100) (map :id (registry/list-instances registry/+default-registry "hello"))) => [:1]
(do ((procedure {:name "hello" :id :1 :interrupt true :handler (fn [] :FAST)} [])) (map :id (registry/list-instances registry/+default-registry "hello"))) => ()
interrupts the existing procedure
(do ((procedure {:name "hello"
:id :1
:handler (fn [] (Thread/sleep 1000000000))} []))
(Thread/sleep 100)
(map :id (registry/list-instances
registry/+default-registry
"hello")))
=> [:1]
(do ((procedure {:name "hello"
:id :1
:interrupt true
:handler (fn [] :FAST)} []))
(map :id (registry/list-instances
registry/+default-registry
"hello")))
=> ()(wrap-mode f)establishes how the computation is going to be run - :sync or :async
(def -a- ((wrap-mode (fn [inst args] inst)) {:mode :async :thread (volatile! nil)} []))
-a- => (contains {:mode :async, :result check/promise? :thread volatile?})
establishes how the computation is going to be run - `:sync` or `:async`
(def -a- ((wrap-mode (fn [inst args] inst))
{:mode :async :thread (volatile! nil)}
[]))
-a-
=> (contains {:mode :async,
:result check/promise?
:thread volatile?})(wrap-registry f)updates the registry of the procedure
@((wrap-registry (fn [inst _] inst)) {:registry (state/cache {}) :name "hello" :id :1} []) => {}
updates the registry of the procedure
@((wrap-registry (fn [inst _] inst))
{:registry (state/cache {}) :name "hello" :id :1}
[])
=> {}(wrap-timeout f)adds timeout to the procedure
@((procedure {:handler (fn [] (Thread/sleep 1000000)) :timeout 100} [])) => (throws java.lang.InterruptedException)
adds timeout to the procedure
@((procedure {:handler (fn [] (Thread/sleep 1000000))
:timeout 100} []))
=> (throws java.lang.InterruptedException)(wrap-timing f)adds timing to the instance (->> ((wrap-timing (fn [inst args] (Thread/sleep 100))) {:mode :async :runtime (atom {})} []) ((juxt #(-> % :ended :long) #(-> % :started :long))) (apply -)) => #(< 50 % 150)
adds timing to the instance
(->> ((wrap-timing (fn [inst args] (Thread/sleep 100)))
{:mode :async
:runtime (atom {})}
[])
((juxt #(-> % :ended :long)
#(-> % :started :long)))
(apply -))
=> #(< 50 % 150)cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |