Interface PendingJavaScriptResult
-
- All Superinterfaces:
Page.ExecutionCanceler,Serializable
- All Known Implementing Classes:
PendingJavaScriptInvocation
public interface PendingJavaScriptResult extends Serializable, Page.ExecutionCanceler
A pending result from a JavaScript snippet sent to the browser for evaluation.If any of the
thenortoCompletableFuturemethods have been invoked before the snippet is sent to the browser, then the there will be an additional round trip for sending the results of the evaluation back to any registered handler. If the JavaScript execution returns aPromise, then the result will be sent to the server only when it is resolved.It is not possible to add handlers after the invocation has been sent to the browser since the original result would in that case already be discarded.
- Since:
- 2.0
- Author:
- Vaadin Ltd
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classPendingJavaScriptResult.JavaScriptExceptionException used when aCompletableFuturereturned fromPendingJavaScriptResultis completed exceptionally because of a client-side error.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleancancelExecution()Cancel the javascript execution, if it was not yet sent to the browser for execution.booleanisSentToBrowser()Checks whether the JavaScript execution has already been sent to the browser.default voidthen(SerializableConsumer<elemental.json.JsonValue> resultHandler)Adds an untyped handler that will be run for a successful execution.voidthen(SerializableConsumer<elemental.json.JsonValue> resultHandler, SerializableConsumer<String> errorHandler)Adds an untyped handler that will be run for a successful execution and a handler that will be run for a failed execution.default <T> voidthen(Class<T> targetType, SerializableConsumer<T> resultHandler)Adds a typed handler that will be run for a successful execution.default <T> voidthen(Class<T> targetType, SerializableConsumer<T> resultHandler, SerializableConsumer<String> errorHandler)Adds a typed handler that will be run for a successful execution and a handler that will be run for a failed execution.default CompletableFuture<elemental.json.JsonValue>toCompletableFuture()Creates an untyped completable future that will be completed with the result of the execution.default <T> CompletableFuture<T>toCompletableFuture(Class<T> targetType)Creates a typed completable future that will be completed with the result of the execution.
-
-
-
Method Detail
-
cancelExecution
boolean cancelExecution()
Cancel the javascript execution, if it was not yet sent to the browser for execution.- Specified by:
cancelExecutionin interfacePage.ExecutionCanceler- Returns:
trueif the execution was canceled,falseif not
-
isSentToBrowser
boolean isSentToBrowser()
Checks whether the JavaScript execution has already been sent to the browser. It is no longer possible to cancel the execution or add a handler for the result after the execution has been sent.- Returns:
trueif the execution is sent to the browser,falseif it's still pending
-
then
default <T> void then(Class<T> targetType, SerializableConsumer<T> resultHandler, SerializableConsumer<String> errorHandler)
Adds a typed handler that will be run for a successful execution and a handler that will be run for a failed execution. One of the handlers will be invoked asynchronously when the result of the execution is sent back to the server.Handlers can only be added before the execution has been sent to the browser.
- Parameters:
targetType- the type to convert the JavaScript return value to, notnullresultHandler- a handler for the return value from a successful execution, notnullerrorHandler- a handler for an error message in case the execution failed, ornullto ignore errors
-
then
default <T> void then(Class<T> targetType, SerializableConsumer<T> resultHandler)
Adds a typed handler that will be run for a successful execution. The handler will be invoked asynchronously if the execution was successful. In case of a failure, no handler will be run.A handler can only be added before the execution has been sent to the browser.
- Parameters:
targetType- the type to convert the JavaScript return value to, notnullresultHandler- a handler for the return value from a successful execution, notnull
-
toCompletableFuture
default <T> CompletableFuture<T> toCompletableFuture(Class<T> targetType)
Creates a typed completable future that will be completed with the result of the execution. It will be completed asynchronously when the result of the execution is sent back to the server. It is not possible to synchronously wait for the result of the execution while holding the session lock since the request handling thread that makes the result available will also need to lock the session.A completable future can only be created before the execution has been sent to the browser.
- Parameters:
targetType- the type to convert the JavaScript return value to, notnull- Returns:
- a completable future that will be completed based on the
execution results, not
null
-
then
void then(SerializableConsumer<elemental.json.JsonValue> resultHandler, SerializableConsumer<String> errorHandler)
Adds an untyped handler that will be run for a successful execution and a handler that will be run for a failed execution. One of the handlers will be invoked asynchronously when the result of the execution is sent back to the server. It is not possible to synchronously wait for the result of the execution while holding the session lock since the request handling thread that makes the result available will also need to lock the session.Handlers can only be added before the execution has been sent to the browser.
- Parameters:
resultHandler- a handler for the JSON representation of the value from a successful execution, notnullerrorHandler- a handler for an error message in case the execution failed, ornullto ignore errors
-
then
default void then(SerializableConsumer<elemental.json.JsonValue> resultHandler)
Adds an untyped handler that will be run for a successful execution. The handler will be invoked asynchronously if the execution was successful. In case of a failure, no handler will be run.A handler can only be added before the execution has been sent to the browser.
- Parameters:
resultHandler- a handler for the JSON representation of the return value from a successful execution, notnull
-
toCompletableFuture
default CompletableFuture<elemental.json.JsonValue> toCompletableFuture()
Creates an untyped completable future that will be completed with the result of the execution. It will be completed asynchronously when the result of the execution is sent back to the server.A completable future can only be created before the execution has been sent to the browser.
- Returns:
- a completable future that will be completed based on the
execution results, not
null
-
-