Futura Api Documentation

Version: 0.3.0

futura.promise

A promise implementation for Clojure that uses jdk8 completable futures behind the scenes.

all

(all promises)

Given an array of promises, return a promise that is resolved when all the items in the array are resolved.

any

(any promises)

Given an array of promises, return a promise that is resolved when first one item in the array is resolved.

catch

(catch p callback)

Catch all promise chain helper.

deliver

(deliver p)(deliver p v)

Mark the promise as completed or rejected with optional value.

If value is not specified nil will be used. If the value is instance of Throwable the promise will be rejected.

done?

(done? p)

Returns true if promise p is done independently if successfully o exceptionally.

IPromise

protocol

A basic promise abstraction.

IPromiseState

protocol

Additional state related abstraction.

pending?

(pending? p)

Returns true if promise p is stil in pending state.

promise

(promise)(promise v)

A promise constructor.

This is a polymorphic function and this is a list of possible arguments:

  • throwable
  • plain value
  • factory function

In case of the initial value is instance of Throwable, rejected promise will be retrned. In case of a plain value (not throwable), a resolved promise will be returned. And finally, if a function or any callable is provided, that function will be executed with one argument as callback for mark the promise resolved or rejected.

(promise (fn [deliver]
           (future
             (Thread/sleep 200)
             (deliver 1))))

The body of that function can be asynchronous and the promise can be freely resolved in other thread.

promise->future

(promise->future p)

Converts a promise in a CompletableFuture instance.

promise?

(promise? p)

Returns true if p is a promise instance.

reason

(reason p)

Get the rejection reason of this promise. Throws an error if the promise isn’t rejected.

rejected?

(rejected? p)

Returns true if promise p is completed exceptionally.

resolved

(resolved v)

Return a promise in a resolved state with given v value.

resolved?

(resolved? p)

Returns true if promise p is completed successfully.

then

(then p callback)

A chain helper for promises.