Liking cljdoc? Tell your friends :D

hara.function.procedure.middleware


wrap-cachedclj

(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}
raw docstring

wrap-callbackclj

(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))}
            []))
raw docstring

wrap-idclj

(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
raw docstring

wrap-instanceclj

(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
raw docstring

wrap-interruptclj

(wrap-interrupt f)

interrupts the existing procedure

(do ((procedure {:name "hello" :id :1 :handler (fn [] (Thread/sleep 1000000000))} []))

(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))} []))

    (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")))
=> ()
raw docstring

wrap-modeclj

(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?})
raw docstring

wrap-registryclj

(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}
  [])
=> {}
raw docstring

wrap-timeoutclj

(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)
raw docstring

wrap-timingclj

(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)
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close