C
- the type of the result valuepublic interface Promise<C>
The future result of an operation, either a value if the operation succeeded, or a failure if the operation failed.
Modifier and Type | Interface and Description |
---|---|
static class |
Promise.Completable<S>
A CompletableFuture that is also a Promise.
|
Modifier and Type | Field and Description |
---|---|
static Promise<?> |
NOOP
Shared instance whose methods are implemented empty,
use
noop() to ease type inference. |
Modifier and Type | Method and Description |
---|---|
default BiConsumer<C,Throwable> |
complete()
Returns a
BiConsumer that, when invoked,
completes this Promise. |
static <T> Promise<T> |
complete(BiConsumer<T,Throwable> fn)
Returns a Promise that, when completed,
invokes the given
BiConsumer function. |
default void |
fail(Throwable failure)
Callback to invoke when the operation fails.
|
static <T> Promise<T> |
from(Consumer<T> succeed,
Consumer<Throwable> fail) |
static <T> Promise<T> |
noop() |
default void |
succeed(C result)
Callback to invoke when the operation succeeds.
|
default void succeed(C result)
Callback to invoke when the operation succeeds.
result
- the resultfail(Throwable)
default void fail(Throwable failure)
Callback to invoke when the operation fails.
failure
- the operation failuredefault BiConsumer<C,Throwable> complete()
Returns a BiConsumer
that, when invoked,
completes this Promise.
Typical usage is with CompletableFuture
:
public void process(ServerMessage message, Promise<Boolean> promise) { CompletableFuture.supplyAsync(() -> asyncOperation(message)) .whenComplete(promise.complete()); }
Promise.Completable
static <T> Promise<T> noop()
T
- the type of the empty resultstatic <T> Promise<T> from(Consumer<T> succeed, Consumer<Throwable> fail)
T
- the type of the result valuesucceed
- the Consumer to call in case of successful completionfail
- the Consumer to call in case of failed completionstatic <T> Promise<T> complete(BiConsumer<T,Throwable> fn)
Returns a Promise that, when completed,
invokes the given BiConsumer
function.
T
- the type of the result valuefn
- the function to invoke when the Promise is completedCopyright © 2008–2024 The CometD Project. All rights reserved.