public interface JsPromise extends JsObject, Closeable
Promise
.
Allows using Java code as promise handlers. The Promise
object is alive while the web
page where it was created is loaded. When the web page is unloaded, all the JavaScript objects
are disposed. An attempt to access the already disposed JavaScript Promise will lead to the
IllegalStateException
.
Usage example:
JsPromise jsPromise = frame.executeJavaScript("Promise.resolve('Resolved')");
jsPromise.then(results -> System.out.println(results[0]));
Modifier and Type | Method and Description |
---|---|
JsPromise |
catchError(JsPromiseHandler onRejected)
Registers a rejection handler for this promise and returns a new one.
|
JsPromise |
finallyExecute(JsPromiseHandler onFinally)
Registers a handler that will be invoked if the promise is settled (fulfilled/rejected) and
returns a new promise.
|
JsPromise |
then(JsPromiseHandler onFulfilled)
Registers a fulfillment handler for this promise and returns a new one.
|
JsPromise |
then(JsPromiseHandler onFulfilled,
JsPromiseHandler onRejected)
Registers fulfillment and rejection handlers for this promise and returns a new one.
|
call, frame, hasProperty, ownPropertyNames, property, propertyNames, putProperty, removeProperty
JsPromise then(JsPromiseHandler onFulfilled, JsPromiseHandler onRejected)
The appropriate handler is called immediately if the promise is already settled.
onFulfilled
- a handler that is invoked if the promise is fulfilledonRejected
- a handler that is invoked if the promise is rejectedjava.lang.IllegalStateException
- if the JavaScript promise is already disposedJsPromiseHandler
JsPromise then(JsPromiseHandler onFulfilled)
The handler is called immediately if the promise is already fulfilled.
onFulfilled
- a handler that is invoked if the promise is fulfilledjava.lang.IllegalStateException
- if the JavaScript promise is already disposedJsPromiseHandler
JsPromise catchError(JsPromiseHandler onRejected)
The handler is called immediately if the promise is already rejected.
onRejected
- a handler that is invoked if the promise is rejectedjava.lang.IllegalStateException
- if the JavaScript promise is already disposedJsPromiseHandler
JsPromise finallyExecute(JsPromiseHandler onFinally)
The handler is called immediately if the promise is already settled.
onFinally
- a handler that is invoked if the promise is settledjava.lang.IllegalStateException
- if the JavaScript promise is already disposedJsPromiseHandler