Liking cljdoc? Tell your friends :D

whew.core

A number of wrappers on top of CompletableFuture.

A number of wrappers on top of CompletableFuture.
raw docstring

->futureclj

(->future x)

Turn a value into a future. Relies on the IFuture protocol.

Turn a value into a future. Relies on the
`IFuture` protocol.
sourceraw docstring

-FUNC-FOLDERclj

A special Function instance to fold/collapse nested futures into a flat one.

A special Function instance to fold/collapse
nested futures into a flat one.
sourceraw docstring

all-ofclj

(all-of futures)

Accepts a collection of values or futures and returns a new future with a vector of values in the same order.

Accepts a collection of values or futures and
returns a new future with a vector of values
in the same order.
sourceraw docstring

any-ofclj

(any-of futures)

Accepts a collection of values or futures. Returns a new future with a value from the first completed (or failed) future.

Accepts a collection of values or futures. Returns
a new future with a value from the first completed
(or failed) future.
sourceraw docstring

biconsumercljmacro

(biconsumer [a b] & body)
source

bifunctioncljmacro

(bifunction [a b] & body)
source

cancelclj

(cancel f)

Try to cancel a given future.

Try to cancel a given future.
sourceraw docstring

cancelled?clj

(cancelled? f)

Check if a future has been canceled.

Check if a future has been canceled.
sourceraw docstring

catchcljmacro

(catch f [e] & body)

Handles an exception that comes from a future. The e binding argument is assigned to an exception instance. The exception is unwrapped in advance meaning instead of ExecutionException you'll get its cause.

Returns a new CompletableFuture instance with a value produced by a block of code.

Handles an exception that comes from a future.
The `e` binding argument is assigned to an exception
instance. The exception is unwrapped in advance
meaning instead of ExecutionException you'll get
its cause.

Returns a new CompletableFuture instance with a value
produced by a block of code.
sourceraw docstring

catch-fnclj

(catch-fn f func)
(catch-fn f func & args)

Like catch but accepts a 1-arity function that handles an unwrapped exception.

Like `catch` but accepts a 1-arity function
that handles an unwrapped exception.
sourceraw docstring

chaincljmacro

(chain f & funcs)

Pass a future though a series of 1-arity functions, each one accepting a value and returning either a new value or a future.

Pass a future though a series of 1-arity functions,
each one accepting a value and returning either
a new value or a future.
sourceraw docstring

derefclj

(deref f)
(deref f timeout-ms timeout-val)

Like the standard deref but flattens a nested future before .get-ting a value from it. Might be called with a timeout and a default value.

Like the standard `deref` but flattens a nested
future before .get-ting a value from it. Might
be called with a timeout and a default value.
sourceraw docstring

e-unwrapclj

(e-unwrap e)

Given a CompletionException or ExecutionException instance, dig recursively for a wrapped exception.

Given a CompletionException or ExecutionException
instance, dig recursively for a wrapped exception.
sourceraw docstring

enumerateclj

(enumerate coll)
source

EXECUTOR_CLJ_POOLEDclj

source

EXECUTOR_CLJ_SOLOclj

source

EXECUTOR_DEFAULTclj

source

EXECUTOR_FJ_COMMONclj

source

failed?clj

(failed? f)

Check if a future instance has already failed. For non-future values, return nil.

Check if a future instance has already failed.
For non-future values, return nil.
sourceraw docstring

foldclj

(fold f)

Turn a future that returns a future, that returns a future, and so on... into a one-level future.

Turn a future that returns a future, that returns
a future, and so on... into a one-level future.
sourceraw docstring

forcljmacro

(for bindings & body)

Like for but:

  • each body expression is wrapped into a future;
  • the result is a future with a vector of values in the same order.

All the default for features are supported (:let, :when and so on).

@(for [x [1 2 3]] {:x x}) [{:x 1} {:x 2} {:x 3}]

Like `for` but:
- each body expression is wrapped into a future;
- the result is a future with a vector of values
  in the same order.

All the default `for` features are supported (:let,
:when and so on).

@(for [x [1 2 3]]
  {:x x})
[{:x 1} {:x 2} {:x 3}]
sourceraw docstring

functioncljmacro

(function [this bind] & body)

Produce a Function instance from a block of code. The first binding argument represents the instance for recursive calls. The second argument is bound to the incoming parameter.

Produce a Function instance from a block of code.
The first binding argument represents the instance
for recursive calls. The second argument is bound
to the incoming parameter.
sourceraw docstring

FUT_ARR_CLASSclj

source

futurecljmacro

(future & body)

Acts like future-async.

Acts like `future-async`.
sourceraw docstring

future-arrayclj

(future-array coll)

Turn a Clojure collection of CompletableFuture instances into a native array.

Turn a Clojure collection of CompletableFuture
instances into a native array.
sourceraw docstring

future-array?clj

(future-array? x)

Is it a native array of CompletableFuture instances?

Is it a native array of CompletableFuture instances?
sourceraw docstring

future-asynccljmacro

(future-async & body)

Produce an asynchronous CompletableFuture instance from a block of code.

Produce an asynchronous CompletableFuture
instance from a block of code.
sourceraw docstring

future-synccljmacro

(future-sync & body)

Evaluate a block of code and emit a completed future instance with the result. The block is executed synchronously in the current thread.

Evaluate a block of code and emit a completed
future instance with the result. The block is
executed synchronously in the current thread.
sourceraw docstring

future-viacljmacro

(future-via [executor] & body)

Spawn a new CompletableFuture within a custom executor instance (e.g. a fixed thread executor pool, virtual executor and so on).

Spawn a new CompletableFuture within a custom executor
instance (e.g. a fixed thread executor pool, virtual
executor and so on).
sourceraw docstring

future?clj

(future? x)

Check if a given argument is an instance of CompletableFuture.

Check if a given argument is an instance
of CompletableFuture.
sourceraw docstring

handlecljmacro

(handle f [r e] & body)

Handles both a result and a possible exception in place.

  • r is bound to a result, or nil;
  • e is bount to an exception, or nil;
  • body is an arbitrary block of code that checks if e is nil and produces either a value, a future or throws an exception.

@(-> (future 42) (handle [r e] (if e {:error (ex-message e)} (future (inc r))))) 43

Returns a new future.

Handles both a result and a possible exception in place.
- r is bound to a result, or nil;
- e is bount to an exception, or nil;
- body is an arbitrary block of code that checks if
  e is nil and produces either a value, a future or
  throws an exception.

@(-> (future 42)
     (handle [r e]
       (if e
         {:error (ex-message e)}
         (future (inc r)))))
43

Returns a new future.
sourceraw docstring

handle-fncljmacro

(handle-fn f func)

Like handle but accepts 2-arity function with a result and an exception. Returns a new future.

Like `handle` but accepts 2-arity function with
a result and an exception. Returns a new future.
sourceraw docstring

IFuturecljprotocol

-to-futureclj

(-to-future x)
source

letcljmacro

(let bindings & body)

Like let but:

  • each binding value might produce a future;
  • the body will be executed with dereferenced values when all the futures are ready.

Binding should not depend on each other (overlap). The result is a new CompletableFuture instance with a valur produced by the block of code.

@(let [a (future (future 1)) b (future (future 2))] (+ a b)) 3

Like `let` but:
- each binding value might produce a future;
- the body will be executed with dereferenced
  values when all the futures are ready.

Binding should not depend on each other (overlap).
The result is a new CompletableFuture instance
with a valur produced by the block of code.

@(let [a (future (future 1))
       b (future (future 2))]
  (+ a b))
3
sourceraw docstring

loopcljmacro

(loop bindings & body)

Like loop but produces a future that produces a fututure that produces... and so on. Key features:

  • return a future with a handler that calls itself recursively;
  • binding values can be futures as well;
  • for recur, there is a special macro with the same naem (don't mix it with the standard recur).

@(loop [i 0 acc []] (if (< i 3) (recur (inc i) (future (future (conj acc i)))) (future (future acc)))) [1 2 3]

Like `loop` but produces a future that produces
a fututure that produces... and so on. Key features:

- return a future with a handler that calls itself
  recursively;
- binding values can be futures as well;
- for recur, there is a special macro with the same
  naem (don't mix it with the standard recur).

@(loop [i 0
          acc []]
   (if (< i 3)
     (recur (inc i)
              (future
                (future
                  (conj acc i))))
     (future
       (future
         acc))))
[1 2 3]
sourceraw docstring

mapclj

(map f coll)
(map f coll & colls)

Like map but works with collection(s) of futures. Any value of a collection might be a future. The f function gets applied with then-fn. It might produce a future as well.

Can accept multiple collections; arity of the f function should match the number of collections. Every nth future is taken from collections, and one all of them are ready, plain values are passed into a function.

Return a lazy collection of futures.

Like `map` but works with collection(s) of futures.
Any value of a collection might be a future. The `f`
function gets applied with `then-fn`. It might produce
a future as well.

Can accept multiple collections; arity of the  `f` function
should match the number of collections. Every nth future
is taken from collections, and one all of them are ready,
plain values are passed into a function.

Return a lazy collection of futures.
sourceraw docstring

recurcljmacro

(recur & args)

A special value for loop (see below).

A special value for loop (see below).
sourceraw docstring

recur?clj

(recur? x)
source

set-executor!clj

(set-executor! executor)

Set a default global executor for all async futures.

Set a default global executor for all async futures.
sourceraw docstring

suppliercljmacro

(supplier & body)

Produce a Supplier instance from a block of code.

Produce a Supplier instance from a block of code.
sourceraw docstring

thencljmacro

(then f [bind] & body)

Apply a block of code to a future. Better used with the -> macro as follows:

(-> (future 42) (then [x] (let [a 1 b 2] (+ a b x))))

The first argument is a future, which might be nested. The second binding artument is a value that comes from the future. The block of code produces a new value for the future. It might return another future as well.

Return a new CompletableFuture instance.

Apply a block of code to a future. Better used
with the -> macro as follows:

(-> (future 42)
    (then [x]
      (let [a 1 b 2]
        (+ a b x))))

The first argument is a future, which might be nested.
The second binding artument is a value that comes
from the future. The block of code produces a new
value for the future. It might return another future
as well.

Return a new CompletableFuture instance.
sourceraw docstring

then-fnclj

(then-fn f func)
(then-fn f func & args)

Like then but accepts a function that accepts a result of a future, and produces either a new value or a future.

(-> (future 42) (then-fn inc))

Also accepts additional arguments to the function:

(-> (future 42) (then-fn + 1 2 3))

Return a new CompletableFuture instance.

Like `then` but accepts a function that accepts
a result of a future, and produces either a new
value or a future.

(-> (future 42)
    (then-fn inc))

Also accepts additional arguments to the function:

(-> (future 42)
    (then-fn + 1 2 3))

Return a new CompletableFuture instance.
sourceraw docstring

throw!cljmacro

(throw! message)
(throw! message & args)
source

timeoutcljmacro

(timeout f timeout-ms)
(timeout f timeout-ms & body)

A macro to set timeout for given future. Without a block of code, just limits the execution time. When time is up, a future ends up with a timeout exception.

If the block of code presents, it provides a value for a future should it completes due to timeout.

Examples:

;; let this future spend up to 1 second but no more (-> (future (some-long-action ...)) (timeout 1000))

;; the same but provide a fallback (-> (future (some-long-action ...)) (timeout 1000 (log/error ....) {:error 'try next time'}))

A macro to set timeout for given future. Without
a block of code, just limits the execution time.
When time is up, a future ends up with a timeout
exception.

If the block of code presents, it provides a value
for a future should it completes due to timeout.

Examples:

;; let this future spend up to 1 second but no more
(-> (future (some-long-action ...))
    (timeout 1000))

;; the same but provide a fallback
(-> (future (some-long-action ...))
    (timeout 1000
       (log/error ....)
       {:error 'try next time'}))
sourceraw docstring

zipcljmacro

(zip & forms)

Turn a number of forms into futures. Return a new CompletableFuture instance with a vector of values in the same order.

@(zip 1 (future 2) 3) [1 2 3]

Turn a number of forms into futures. Return a new
CompletableFuture instance with a vector of values
in the same order.

@(zip 1 (future 2) 3)
[1 2 3]
sourceraw docstring

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

× close