public interface PendingJavaScriptResult extends Page.ExecutionCanceler
If any of the then
or toCompletableFuture
methods
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 a
Promise
, 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.
Modifier and Type | Interface and Description |
---|---|
static class |
PendingJavaScriptResult.JavaScriptException
Exception used when a
CompletableFuture returned from
PendingJavaScriptResult is completed exceptionally because of a
client-side error. |
Modifier and Type | Method and Description |
---|---|
boolean |
cancelExecution()
Cancel the javascript execution, if it was not yet sent to the
browser for execution.
|
boolean |
isSentToBrowser()
Checks whether the JavaScript execution has already been sent to the
browser.
|
default <T> void |
then(Class<T> targetType,
SerializableConsumer<T> resultHandler)
Adds a typed handler that will be run for a successful execution.
|
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.
|
default void |
then(SerializableConsumer<elemental.json.JsonValue> resultHandler)
Adds an untyped handler that will be run for a successful execution.
|
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.
|
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.
|
boolean cancelExecution()
Page.ExecutionCanceler
cancelExecution
in interface Page.ExecutionCanceler
true
if the execution was canceled,
false
if notboolean isSentToBrowser()
true
if the execution is sent to the browser,
false
if it's still pendingdefault <T> void then(Class<T> targetType, SerializableConsumer<T> resultHandler, SerializableConsumer<String> errorHandler)
Handlers can only be added before the execution has been sent to the browser.
targetType
- the type to convert the JavaScript return value to, not
null
resultHandler
- a handler for the return value from a successful execution,
not null
errorHandler
- a handler for an error message in case the execution failed,
or null
to ignore errorsdefault <T> void then(Class<T> targetType, SerializableConsumer<T> resultHandler)
A handler can only be added before the execution has been sent to the browser.
targetType
- the type to convert the JavaScript return value to, not
null
resultHandler
- a handler for the return value from a successful execution,
not null
default <T> CompletableFuture<T> toCompletableFuture(Class<T> targetType)
A completable future can only be created before the execution has been sent to the browser.
targetType
- the type to convert the JavaScript return value to, not
null
null
void then(SerializableConsumer<elemental.json.JsonValue> resultHandler, SerializableConsumer<String> errorHandler)
Handlers can only be added before the execution has been sent to the browser.
resultHandler
- a handler for the JSON representation of the value from a
successful execution, not null
errorHandler
- a handler for an error message in case the execution failed,
or null
to ignore errorsdefault void then(SerializableConsumer<elemental.json.JsonValue> resultHandler)
A handler can only be added before the execution has been sent to the browser.
resultHandler
- a handler for the JSON representation of the return value from
a successful execution, not null
default CompletableFuture<elemental.json.JsonValue> toCompletableFuture()
A completable future can only be created before the execution has been sent to the browser.
null
Copyright © 2023. All rights reserved.