java.lang.Object
com.jpro.webapi.JSVariable
com.jpro.webapi.PromiseJSVariable
This class represents a variable in the JS-scope of the client, which is a promise.
It provides the same functionality as a JSVariable, but has additional methods to handle the promise.
-
Constructor Summary
ConstructorsConstructorDescriptionPromiseJSVariable
(JSVariable jsVariable) Constructs a new PromiseJSVariable using an existing JSVariable. -
Method Summary
Modifier and TypeMethodDescriptionResolves the JavaScript promise and retrieves its value as a string.Returns a CompletableFuture that is completed when the underlying JavaScript promise is resolved.void
onPromiseError
(Consumer<Throwable> errorHandler) Registers an error handler for the promise.Resolves the underlying JavaScript promise and returns a CompletableFuture that contains the JSVariable representing the resolved promise.Methods inherited from class com.jpro.webapi.JSVariable
futureToPromise, getName, getString, getWebAPI, isPromise, onComplete, onError, promiseToFuture, toPromise
-
Constructor Details
-
PromiseJSVariable
Constructs a new PromiseJSVariable using an existing JSVariable.- Parameters:
jsVariable
- the JSVariable that is being wrapped as a promise
-
-
Method Details
-
getPromiseString
Resolves the JavaScript promise and retrieves its value as a string. This method first ensures that the promise is resolved by callingresolveVariable()
, then converts the resolved value to a string.- Returns:
- a
CompletableFuture
that, when completed, provides the string value of the resolved promise.
-
onPromiseComplete
Returns a CompletableFuture that is completed when the underlying JavaScript promise is resolved. This does not provide the value of the promise but rather signifies its completion. If an error occurs, the future will be completed exceptionally.- Returns:
- a
CompletableFuture
that is completed when the promise is resolved
-
onPromiseError
Registers an error handler for the promise. This handler is invoked if the promise encounters an error during its resolution.- Parameters:
errorHandler
- the consumer to handle errors
-
resolveVariable
Resolves the underlying JavaScript promise and returns a CompletableFuture that contains the JSVariable representing the resolved promise.- Returns:
- a
CompletableFuture
containing the JSVariable once the promise is resolved
-