zensols.actioncli.util
Utility functions
defnlock
macro
(defnlock attr-map? name doc-string? [params*] body)
(defnlock name doc-string? [params*] body)
(defnlock name [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
.
defnpool
macro
(defnpool attr-map? name [symbol factory-fn config?] doc-string? [params*] body)
(defnpool name [symbol config factory-fn] doc-string? [params*] body)
(defnpool name [symbol config factory-fn] [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.
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 for more information.
defnprime
macro
(defnprime attr-map? name doc-string? [params*] body)
(defnprime name doc-string? [params*] body)
(defnprime name [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
.
pool-item-status
(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.
trunc
(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*.
with-timeout
macro
(with-timeout timeout-millis & body)
Execute body and timeout after timeout-millis milliseconds.
If the execution times out java.util.concurrent.TimeoutException
is thrown.