A promise represents a value that may not be available yet. The primary method for interacting with a promise is its Completable.compose() method. A promise is a Completable element restricted to a single value.

By: Julien Viet

no subtypes hierarchy

Initializer
Promise()
Attributes
futureSource Codeshared Future<Value> future

Create and return a future for this promise. The future allows to follow the resolution of the promise in a blocking fashion:

  • if this promise is fulfilled then the future will return the value, or
  • if this promise is rejected then the future will return the reason.

This class should be used when a thread needs to block until this promise is resolved only, i.e it defeats the purpose of the promise programming model.

promiseSource Codeshared actual Promise<[Value]> promise

The promise.

Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Promised<Value>
Methods
andSource Codeshared actual Term<Value|Other,[Other, Value]> and<Other>(Promise<Other> other)

Combine the current term with a provided promise and return a new term object that

  • fulfills when both the current term and the other promise are fulfilled, and
  • rejects when either the current term or the other promise is rejected.

The Term's promise will be

  • fulfilled with a tuple of values of the original promise (it is important to notice that tuple elements are in reverse order of the and chain), or
  • rejected with the reason of the rejected promise.

The Term object allows for promise chaining as a fluent API:

Promise<String> p1 = ...
Promise<Integer> p2 = ...
Promise<Boolean> p3 = ...
p1.and(p2, p3)
  .compose((Boolean b, Integer i, String s) 
            => doSomething(b, i, s));
Refines Term.and
Inherited Methods
Methods inherited from: Object
Methods inherited from: Completable<Value>
Methods inherited from: Term<Element,T>