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
(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.
Takes input exception and return the original exception cause (if
any). This unwraps ExecutionException
and CompletionException
Takes input exception and return the original exception cause (if any). This unwraps `ExecutionException` and `CompletionException`
(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)
manifold.let-flow
port
manifold.`let-flow` port
(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.
(unwrap f)
Tries to deref a Future, returns a value upon completion or the original exception that triggered exceptional termination (as opposed to a wrapped exception)
Tries to deref a Future, returns a value upon completion or the original exception that triggered exceptional termination (as opposed to a wrapped exception)
(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