Completion provides base support for promises and their composition. This interface satisfies the Promised interface, to be used when a Promise is needed

By: Julien Viet

no type hierarchy

Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Promised<Value>
Methods
andSource Codeshared formal Completion<Element|Other,Tuple<Element|Other,Other,T>> and<Other>(Promise<Other> other)

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

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

The Completion'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 Completion 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));
completedSource Codeshared default void completed(Anything(*T) onFulfilled, Anything(Throwable) onRejected = ...)

When completion happens, the provided function will be invoked.

Parameters:
  • onFulfilled

    A function that is called when fulfilled.

  • onRejected = rethrow

    A function that is called when rejected.

flatMapSource Codeshared formal Promise<Result> flatMap<Result>(Promise<Result>(*T) onFulfilled, Promise<Result>(Throwable) onRejected = ...)

Compose and return a Promise

Parameters:
  • onFulfilled

    A function that is called when fulfilled.

  • onRejected = rethrow

    A function that is called when rejected.

mapSource Codeshared formal Promise<Result> map<Result>(Result(*T) onFulfilled, Result(Throwable) onRejected = ...)

Compose and return a Promise with map functions

Parameters:
  • onFulfilled

    A function that is called when fulfilled.

  • onRejected = rethrow

    A function that is called when rejected.

Inherited Methods
Methods inherited from: Object