Package com.teamdev.jxbrowser.js
Interface JsPromise
- All Superinterfaces:
AutoCloseable
,Closeable
,JsObject
A JavaScript
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]));
-
Method Summary
Modifier and TypeMethodDescriptioncatchError
(JsPromiseHandler onRejected) Registers a rejection handler for this promise and returns a new one.finallyExecute
(JsPromiseHandler onFinally) Registers a handler that will be invoked if the promise is settled (fulfilled/rejected) and returns a new promise.then
(JsPromiseHandler onFulfilled) Registers a fulfillment handler for this promise and returns a new one.then
(JsPromiseHandler onFulfilled, JsPromiseHandler onRejected) Registers fulfillment and rejection handlers for this promise and returns a new one.Methods inherited from interface com.teamdev.jxbrowser.js.JsObject
call, close, frame, hasProperty, ownPropertyNames, property, propertyNames, putProperty, removeProperty
-
Method Details
-
then
Registers fulfillment and rejection handlers for this promise and returns a new one.The appropriate handler is called immediately if the promise is already settled.
- Parameters:
onFulfilled
- a handler that is invoked if the promise is fulfilledonRejected
- a handler that is invoked if the promise is rejected- Throws:
ObjectClosedException
- if the JavaScript promise is already disposed- See Also:
-
then
Registers a fulfillment handler for this promise and returns a new one.The handler is called immediately if the promise is already fulfilled.
- Parameters:
onFulfilled
- a handler that is invoked if the promise is fulfilled- Throws:
ObjectClosedException
- if the JavaScript promise is already disposed- See Also:
-
catchError
Registers a rejection handler for this promise and returns a new one.The handler is called immediately if the promise is already rejected.
- Parameters:
onRejected
- a handler that is invoked if the promise is rejected- Throws:
ObjectClosedException
- if the JavaScript promise is already disposed- See Also:
-
finallyExecute
Registers a handler that will be invoked if the promise is settled (fulfilled/rejected) and returns a new promise.The handler is called immediately if the promise is already settled.
- Parameters:
onFinally
- a handler that is invoked if the promise is settled- Throws:
ObjectClosedException
- if the JavaScript promise is already disposed- See Also:
-