Promise.Completable
public interface Promise<C>
Modifier and Type | Interface | Description |
---|---|---|
static class |
Promise.Completable<S> |
A CompletableFuture that is also a Promise.
|
Modifier and Type | Field | Description |
---|---|---|
static Promise<?> |
NOOP |
Shared instance whose methods are implemented empty,
|
Modifier and Type | Method | Description |
---|---|---|
default java.util.function.BiConsumer<C,java.lang.Throwable> |
complete() |
Returns a
BiConsumer that, when invoked,
completes this Promise. |
default void |
fail(java.lang.Throwable failure) |
Callback to invoke when the operation fails.
|
static <T> Promise<T> |
from(java.util.function.Consumer<T> succeed,
java.util.function.Consumer<java.lang.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(java.lang.Throwable failure)
Callback to invoke when the operation fails.
failure
- the operation failuredefault java.util.function.BiConsumer<C,java.lang.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()
static <T> Promise<T> from(java.util.function.Consumer<T> succeed, java.util.function.Consumer<java.lang.Throwable> fail)
succeed
- the Consumer to call in case of successful completionfail
- the Consumer to call in case of failed completionCopyright © 2008–2017 The CometD Project. All rights reserved.