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

By: Julien Viet

no subtypes hierarchy

contextSource Codeshared formal ExecutionContext context

The context of this promise

promiseSource Codeshared actual Promise<[Value]> promise

The promise.

Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Promised<Value>
andSource Codeshared actual Completion<Value|Other,[Other, Value]> 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 actual void completed(Anything onFulfilled(Value val), Anything onRejected(Throwable reason))

When completion happens, the provided function will be invoked.

flatMapSource Codeshared formal Promise<Result> flatMap<Result>(Promise<Result> onFulfilled(Value val), Promise<Result> onRejected(Throwable reason))

Compose and return a Promise

mapSource Codeshared formal Promise<Result> map<Result>(Result onFulfilled(Value val), Result onRejected(Throwable reason))

Compose and return a Promise with map functions

onCompleteSource Codeshared void onComplete(void completed(Value|Throwable completion))

Callback when the promise is completed with a function that accepts either a Value or a Throwable.

  • completed

    A function that accepts either the promised value or a Throwable as completion.

Inherited Methods
Methods inherited from: Object
Methods inherited from: Completion<Element,T>