Module jpro.webapi

Class PromiseJSVariable

java.lang.Object
com.jpro.webapi.JSVariable
com.jpro.webapi.PromiseJSVariable

public class PromiseJSVariable extends JSVariable
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 Details

    • PromiseJSVariable

      public PromiseJSVariable(JSVariable jsVariable)
      Constructs a new PromiseJSVariable using an existing JSVariable.
      Parameters:
      jsVariable - the JSVariable that is being wrapped as a promise
  • Method Details

    • getPromiseString

      public CompletableFuture<String> getPromiseString()
      Resolves the JavaScript promise and retrieves its value as a string. This method first ensures that the promise is resolved by calling resolveVariable(), then converts the resolved value to a string.
      Returns:
      a CompletableFuture that, when completed, provides the string value of the resolved promise.
    • onPromiseComplete

      public CompletableFuture<Void> 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

      public void onPromiseError(Consumer<Throwable> errorHandler)
      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

      public CompletableFuture<JSVariable> 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