This provides a clj friendly wrapper for CompletableFuture and adds a few utility functions to mimic manifold features. Shamelessly stole code/ideas from the awesome manifold library.
This provides a clj friendly wrapper for CompletableFuture and adds a few utility functions to mimic manifold features. Shamelessly stole code/ideas from the awesome manifold library.
(chain x & fns)
Composes functions starting with x as argument triggering calls to fns for every step coercing the return values to deferreds if necessary and returns a deferred with the final result.
Composes functions starting with x as argument triggering calls to fns for every step coercing the return values to deferreds if necessary and returns a deferred with the final result.
(chain' x & fns)
Like chain but assumes fns return raw values instead of potential futures
Like chain but assumes fns return raw values instead of potential futures
(chain-futures x & fs)
Like chain but takes a value and functions that will return futures
Like chain but takes a value and functions that will return futures
(do-> m-specs steps & body)
Utility macro to build monadic like constructs like let-flow
Utility macro to build monadic like constructs like `let-flow`
(error-future x)
Returns a new CompletableFuture that is already completed exceptionally with the given exception.
Returns a new CompletableFuture that is already completed exceptionally with the given exception.
(future)
(future f)
(future f executor)
No arg creates an empty/incomplete future, 1 arg creates a future that will get the return value of f as realized value on fork-join common pool, 2 arg creates a future that will be realized on ExecutorService supplied with return value of f as realized value.
The executor that is set at this stage will continue to be used for subsequent steps (then/chain etc) if another one is not specified at another level
No arg creates an empty/incomplete future, 1 arg creates a future that will get the return value of f as realized value on fork-join common pool, 2 arg creates a future that will be realized on ExecutorService supplied with return value of f as realized value. The executor that is set at this stage will continue to be used for subsequent steps (then/chain etc) if another one is not specified at another level
(future? x)
Returns true if x is a CompletableFuture
Returns true if x is a CompletableFuture
(let-flow steps & body)
Like let-flow but supports :when.
(let-flow [x (future (fn [] 0))
:when (= x 0)
y (+ x 1)
z (future (fn [] (inc y)))]
[x y z])```
Like let-flow but supports :when. ``` (let-flow [x (future (fn [] 0)) :when (= x 0) y (+ x 1) z (future (fn [] (inc y)))] [x y z])```
(loop bindings & body)
A version of Clojure's loop which allows for asynchronous loops, via
qbits.auspex/recur
. loop
will always return a CompletableFuture
Value, even if the body is synchronous. Note that loop
does
not coerce values to deferreds, actual qbits.auspex/future
s
must be used.
(loop [i 1e6] (chain (future i) #(if (zero? %) % (recur (dec %)))))
A version of Clojure's loop which allows for asynchronous loops, via `qbits.auspex/recur`. `loop` will always return a CompletableFuture Value, even if the body is synchronous. Note that `loop` does **not** coerce values to deferreds, actual `qbits.auspex/future`s must be used. (loop [i 1e6] (chain (future i) #(if (zero? %) % (recur (dec %)))))
(one & cfs)
Returns one value from a list of futures
Returns one value from a list of futures
(recur & args)
Like recur, but to be used with qbits.auspex/loop
Like recur, but to be used with `qbits.auspex/loop`
(success-future x)
Returns a new CompletableFuture that is already completed with the given value.
Returns a new CompletableFuture that is already completed with the given value.
(zip & xs)
Takes a list of values, some of which can be futures and returns a future that will contains a list of realized values
Takes a list of values, some of which can be futures and returns a future that will contains a list of realized values
(zip' & fs)
Like zip but faster if you know you're only dealing with futures args
Like zip but faster if you know you're only dealing with futures args
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close