Liking cljdoc? Tell your friends :D

flatland.useful.state


Mutablecljprotocol

put!clj

(put! self v)
source

periodic-recomputeclj

(periodic-recompute f duration)

Takes a thunk and a duration (from flatland.useful.time), and yields a function that attempts to pre-cache calls to that thunk. The first time you call the returned function, it starts a background thread that re-computes the thunk's result according to the requested duration.

If you call the returned function with no arguments, it blocks until some cached value is available; with one not-found argument, it returns the not-found value if no cached value has yet been computed.

Take care: if the duration you specify causes your task to be scheduled again while it is still running, the task will wait in a queue. That queue will continue to grow unless your task is able to complete more quickly than the duration you specified.

Takes a thunk and a duration (from flatland.useful.time), and yields a function
that attempts to pre-cache calls to that thunk. The first time you call
the returned function, it starts a background thread that re-computes the
thunk's result according to the requested duration.

If you call the returned function with no arguments, it blocks until
some cached value is available; with one not-found argument, it returns
the not-found value if no cached value has yet been computed.

Take care: if the duration you specify causes your task to be scheduled
again while it is still running, the task will wait in a queue. That queue
will continue to grow unless your task is able to complete more quickly
than the duration you specified.
sourceraw docstring

trade!clj

(trade! atom f & args)

Like swap!, except it returns the old value of the atom.

Like swap!, except it returns the old value of the atom.
sourceraw docstring

volatileclj

(volatile x)
(volatile x & options)

Creates and returns a Volatile with an initial value of x and zero or more options (in any order):

:meta metadata-map

:validator validate-fn

If metadata-map is supplied, it will become the metadata on the Volatile. validate-fn must be nil or a side-effect-free fn of one argument, which will be passed the intended new state on any state change. If the new state is unacceptable, the validate-fn should return false or throw an exception.

Creates and returns a Volatile with an initial value of x and zero or
more options (in any order):

:meta metadata-map

:validator validate-fn

If metadata-map is supplied, it will become the metadata on the
Volatile. validate-fn must be nil or a side-effect-free fn of one
argument, which will be passed the intended new state on any state
change. If the new state is unacceptable, the validate-fn should
return false or throw an exception.
sourceraw docstring

wait-untilclj

(wait-until reference pred)
source

with-altered-rootscljmacro

(with-altered-roots bindings & body)

Use alter-var-root to temporarily modify the root bindings of some vars. For each var, the temporary value will be (apply f current-value args).

bindings should be a vector, each element of which should look like a function call: (with-altered-roots [(+ x 10)] body) ;; sets x to (+ x 10)

Use with caution: this is not thread-safe, and multiple concurrent calls can leave vars' root values in an unpredictable state.

Use alter-var-root to temporarily modify the root bindings of some vars.
 For each var, the temporary value will be (apply f current-value args).

 bindings should be a vector, each element of which should look like a function call:
(with-altered-roots [(+ x 10)] body) ;; sets x to (+ x 10)

 Use with caution: this is not thread-safe, and multiple concurrent calls
 can leave vars' root values in an unpredictable state.
sourceraw docstring

with-altered-varscljmacro

(with-altered-vars bindings & body)

Binds each var-name to the result of (apply f current-value args) for the dynamic scope of body. Basically like swap! or alter, but for vars. bindings should be a vector, each element of which should look like a function call:

(with-altered-vars [(+ x 10)] body) ;; binds x to (+ x 10)

Binds each var-name to the result of (apply f current-value args) for the dynamic
scope of body. Basically like swap! or alter, but for vars. bindings should be a
vector, each element of which should look like a function call:

(with-altered-vars [(+ x 10)] body) ;; binds x to (+ x 10)
sourceraw docstring

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

× close