Utility functions
Utility functions
Default truncation length for trunc
.
Default truncation length for [[trunc]].
(defnlock name [params*] body)
(defnlock name doc-string? [params*] body)
(defnlock attr-map? name doc-string? [params*] body)
Just like defn
but create an atom instance used to generate the result
(resource) by calling body only once.
This creates a function name that invokes body the first time it is invoked. It then caches the solution and returns it on the next call. This is all done in a [[clojure.core/locking]] lexical context to make this first call and resource creation thread-safe.
The result it saves is kept in the metadata under key :init-resource
.
Just like `defn` but create an atom instance used to generate the result (resource) by calling **body** only once. This creates a function **name** that invokes **body** the first time it is invoked. It then caches the solution and returns it on the next call. This is all done in a [[clojure.core/locking]] lexical context to make this first call and resource creation thread-safe. The result it saves is kept in the metadata under key `:init-resource`.
(defnpool name [symbol config factory-fn] [params*] body)
(defnpool name [symbol config factory-fn] doc-string? [params*] body)
(defnpool attr-map? name [symbol factory-fn config?] doc-string? [params*] body)
Create a function called name that pools objects. The pool resources are bound to item-symbol and created with function factory-fn. The config parameter determines how pooling is done with the following default configuration:
{:max-total -1
:max-idle 8
:min-idle 0}
Note: The configuration form is optional.
(defnpool pool1 [pooled-item
#(java.util.Date.)
{:max-total 5}]
[arg1]
(str pooled-item arg1))
Creates a function pool
that takes one argument (arg
), binds pooled items
to pool-item
with new instances of java.util.Date
and has a max pool size
of 5. The output appends the date to the passed argument.
See the underlying Java API for more information.
Create a function called **name** that pools objects. The pool resources are bound to **item-symbol** and created with function **factory-fn**. The **config** parameter determines how pooling is done with the following default configuration: ``` {:max-total -1 :max-idle 8 :min-idle 0} ``` *Note:* The configuration form is optional. ## Example ``` (defnpool pool1 [pooled-item #(java.util.Date.) {:max-total 5}] [arg1] (str pooled-item arg1)) ``` Creates a function `pool` that takes one argument (`arg`), binds pooled items to `pool-item` with new instances of `java.util.Date` and has a max pool size of 5. The output appends the date to the passed argument. See the underlying [Java API](https://commons.apache.org/proper/commons-pool/apidocs/org/apache/commons/pool2/impl/GenericObjectPool.html#setConfig-org.apache.commons.pool2.impl.GenericObjectPoolConfig) for more information.
(defnprime name [params*] body)
(defnprime name doc-string? [params*] body)
(defnprime attr-map? name doc-string? [params*] body)
Just like defn
but call body in a [[clojure.core/locking]] lexical
context to make this first call and resource creation thread-safe.
Subsequent calls only use the monitor to check if the resource has body
been called once.
This creates a function name that invokes body the first time it is invoked. It then caches the solution and returns it on the next call.
The result it saves is kept in the metadata under key :init-resource
.
Just like `defn` but call **body** in a [[clojure.core/locking]] lexical context to make this first call and resource creation thread-safe. Subsequent calls only use the monitor to check if the resource has **body** been called once. This creates a function **name** that invokes **body** the first time it is invoked. It then caches the solution and returns it on the next call. The result it saves is kept in the metadata under key `:init-resource`.
(parse-macro-arguments arg-list)
(pool-item-status pool-fn-var)
Return statistics on the pool-fn-var. A var (not a symbole) needs to be
passed, which look something like '#my-pol-fn
for pool-fn-var.
Return statistics on the **pool-fn-var**. A var (not a symbole) needs to be passed, which look something like `'#my-pol-fn` for **pool-fn-var**.
(trunc obj)
(trunc obj len)
Truncate string obj
at len
characters adding ellipses if larger that a set
length. If obj
isn't a string use pr-str
to make it a string.
See *trunc-len*
.
Truncate string `obj` at `len` characters adding ellipses if larger that a set length. If `obj` isn't a string use `pr-str` to make it a string. See [[*trunc-len*]].
(with-timeout timeout-millis & body)
Execute body and timeout after timeout-millis milliseconds.
If the execution times out java.util.concurrent.TimeoutException
is thrown.
Execute **body** and timeout after **timeout-millis** milliseconds. If the execution times out `java.util.concurrent.TimeoutException` is thrown.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close