public class Promise<T> extends PromiseLike<T>
catch
is
Catch, then
with chained Promise is thenAsync. Lang.async(def.js.Function)
/ Lang.await(def.js.Promise<R>)
. This is sweet!
getAnswer(5000)
.then(result -> {
console.log("you have waited long enough to know that the answer is: " + result);
});
private Promise getAnswer(int millis) {
return new Promise((Consumer resolve, Consumer
Modifier and Type | Class and Description |
---|---|
static interface |
Promise.ExecutorPromiseLikeBiConsumer<T1,T2>
This functional interface should be used for disambiguating lambdas in
function parameters (by casting to this interface).
|
static class |
Promise.IterablePromiseLikeT<T>
This class was automatically generated for disambiguating erased method
signatures.
|
static class |
Promise.IterableT<T>
This class was automatically generated for disambiguating erased method
signatures.
|
Modifier and Type | Field and Description |
---|---|
static Promise<?> |
prototype
A reference to the prototype.
|
constructor
Modifier | Constructor and Description |
---|---|
protected |
Promise() |
|
Promise(BiConsumer<Consumer<T>,Consumer<Object>> executor)
Creates a new Promise.
|
|
Promise(Promise.ExecutorPromiseLikeBiConsumer<Consumer<PromiseLike<T>>,Consumer<Object>> executor)
Creates a new Promise.
|
Modifier and Type | Method and Description |
---|---|
String |
$get(Symbol toStringTag) |
static <T> Promise<T[]> |
all(Iterable<PromiseLike<T>> values)
Creates a Promise that is resolved with an array of results when all of the
provided Promises resolve, or rejected when any Promise is rejected.
|
static <T> Promise<T[]> |
allFromValues(Iterable<T> values)
Creates a Promise that is resolved with an array of results when all of the
provided Promises resolve, or rejected when any Promise is rejected.
|
Promise<T> |
Catch(Consumer<Object> onrejected) |
Promise<T> |
Catch(Function<Object,T> onrejected)
Attaches a callback for only the rejection of the Promise.
|
Promise<T> |
catchAsync(Function<Object,PromiseLike<T>> onrejected)
Attaches a callback for only the rejection of the Promise.
|
static <T> Promise<T> |
race(Promise.IterablePromiseLikeT<T> values)
Creates a Promise that is resolved or rejected when any of the provided
Promises are resolved or rejected.
|
static <T> Promise<T> |
race(Promise.IterableT<T> values)
Creates a Promise that is resolved or rejected when any of the provided
Promises are resolved or rejected.
|
static Promise<Void> |
reject(Object reason)
Creates a new rejected promise for the provided reason.
|
static Promise<Void> |
resolve()
Creates a new resolved promise .
|
static <T> Promise<T> |
resolve(PromiseLike<T> value)
Creates a new resolved promise for the provided value.
|
static <T> Promise<T> |
resolve(T value)
Creates a new resolved promise for the provided value.
|
Promise<Void> |
then(Consumer<T> onfulfilled) |
<TResult> Promise<TResult> |
then(Function<T,TResult> onfulfilled)
Attaches callbacks for the resolution and/or rejection of the Promise.
|
<TResult> Promise<TResult> |
then(Function<T,TResult> onfulfilled,
Consumer<Object> onrejected) |
<TResult> Promise<TResult> |
then(Function<T,TResult> onfulfilled,
Function<Object,TResult> onrejected)
Attaches callbacks for the resolution and/or rejection of the Promise.
|
Promise<Void> |
then(Runnable onfulfilled) |
<TResult> Promise<TResult> |
then(Supplier<TResult> onfulfilled) |
<TResult> Promise<TResult> |
thenAsync(Function<T,PromiseLike<TResult>> onfulfilled)
Attaches callbacks for the resolution and/or rejection of the Promise.
|
<TResult> Promise<TResult> |
thenAsync(Function<T,PromiseLike<TResult>> onfulfilled,
Consumer<Object> onrejected) |
<TResult> Promise<TResult> |
thenAsync(Function<T,PromiseLike<TResult>> onfulfilled,
Function<Object,TResult> onrejected)
Attaches callbacks for the resolution and/or rejection of the Promise.
|
<TResult> Promise<TResult> |
thenAsync(Supplier<PromiseLike<TResult>> onfulfilled) |
<TResult> Promise<TResult> |
thenAsyncOnError(Function<T,TResult> onfulfilled,
Function<Object,PromiseLike<TResult>> onrejected)
Attaches callbacks for the resolution and/or rejection of the Promise.
|
<TResult> Promise<TResult> |
thenAsyncWithOnError(Function<T,PromiseLike<TResult>> onfulfilled,
Function<Object,PromiseLike<TResult>> onrejected)
Attaches callbacks for the resolution and/or rejection of the Promise.
|
then
$applyStatic, $applyStatic, $delete, $delete, $get, $get, $set, $set, $super, assign, create, create, defineProperties, defineProperty, defineProperty, freeze, getOwnPropertyDescriptor, getOwnPropertyNames, getPrototypeOf, hasOwnProperty, hasOwnProperty, hasOwnProperty, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, propertyIsEnumerable, propertyIsEnumerable, seal, toJSString, toLocaleString, toString, valueOf
public static Promise<?> prototype
public Promise(Promise.ExecutorPromiseLikeBiConsumer<Consumer<PromiseLike<T>>,Consumer<Object>> executor)
executor
- A callback used to initialize the promise. This callback is passed
two arguments: a resolve callback used resolve the promise with a
value or the result of another promise, and a reject callback used
to reject the promise with a provided reason or error.public Promise(BiConsumer<Consumer<T>,Consumer<Object>> executor)
executor
- A callback used to initialize the promise. This callback is passed
two arguments: a resolve callback used resolve the promise with a
value or the result of another promise, and a reject callback used
to reject the promise with a provided reason or error.protected Promise()
@Name(value="then") public <TResult> Promise<TResult> then(Function<T,TResult> onfulfilled, Function<Object,TResult> onrejected)
onfulfilled
- The callback to execute when the Promise is resolved.onrejected
- The callback to execute when the Promise is rejected.@Name(value="then") public <TResult> Promise<TResult> then(Function<T,TResult> onfulfilled, Consumer<Object> onrejected)
@Name(value="catch") public Promise<T> Catch(Function<Object,T> onrejected)
onrejected
- The callback to execute when the Promise is rejected.@Name(value="all") public static <T> Promise<T[]> allFromValues(Iterable<T> values)
values
- An array of Promises.public static <T> Promise<T[]> all(Iterable<PromiseLike<T>> values)
values
- An array of Promises.public static <T> Promise<T> race(Promise.IterableT<T> values)
values
- An array of Promises.public static Promise<Void> reject(Object reason)
reason
- The reason the promise was rejected.public static <T> Promise<T> resolve(T value)
value
- A promise.public <TResult> Promise<TResult> then(Function<T,TResult> onfulfilled)
onfulfilled
- The callback to execute when the Promise is resolved.onrejected
- The callback to execute when the Promise is rejected.@Name(value="then") public <TResult> Promise<TResult> thenAsyncOnError(Function<T,TResult> onfulfilled, Function<Object,PromiseLike<TResult>> onrejected)
onfulfilled
- The callback to execute when the Promise is resolved.onrejected
- The callback to execute when the Promise is rejected.@Name(value="then") public <TResult> Promise<TResult> thenAsyncWithOnError(Function<T,PromiseLike<TResult>> onfulfilled, Function<Object,PromiseLike<TResult>> onrejected)
onfulfilled
- The callback to execute when the Promise is resolved.onrejected
- The callback to execute when the Promise is rejected.@Name(value="then") public <TResult> Promise<TResult> thenAsync(Function<T,PromiseLike<TResult>> onfulfilled, Function<Object,TResult> onrejected)
onfulfilled
- The callback to execute when the Promise is resolved.onrejected
- The callback to execute when the Promise is rejected.@Name(value="then") public <TResult> Promise<TResult> thenAsync(Supplier<PromiseLike<TResult>> onfulfilled)
@Name(value="then") public <TResult> Promise<TResult> thenAsync(Function<T,PromiseLike<TResult>> onfulfilled, Consumer<Object> onrejected)
@Name(value="catch") public Promise<T> catchAsync(Function<Object,PromiseLike<T>> onrejected)
onrejected
- The callback to execute when the Promise is rejected.public static <T> Promise<T> race(Promise.IterablePromiseLikeT<T> values)
values
- An array of Promises.public static <T> Promise<T> resolve(PromiseLike<T> value)
value
- A promise.@Name(value="then") public <TResult> Promise<TResult> thenAsync(Function<T,PromiseLike<TResult>> onfulfilled)
onfulfilled
- The callback to execute when the Promise is resolved.onrejected
- The callback to execute when the Promise is rejected.