public interface Callback extends Invocable
A callback abstraction that handles completed/failed events of asynchronous operations.
Semantically this is equivalent to an optimise Promise<Void>, but callback is a more meaningful name than EmptyPromise
Modifier and Type | Interface and Description |
---|---|
static class |
Callback.Completable
A CompletableFuture that is also a Callback.
|
static class |
Callback.Completing |
static interface |
Callback.InvocableCallback |
static class |
Callback.Nested
Nested Completing Callback that completes after
completing the nested callback
|
Invocable.InvocationType
Modifier and Type | Field and Description |
---|---|
static Callback |
NOOP
Instance of Adapter that can be used when the callback methods need an empty
implementation without incurring in the cost of allocating a new Adapter object.
|
__nonBlocking
Modifier and Type | Method and Description |
---|---|
static Callback |
combine(Callback cb1,
Callback cb2) |
default void |
failed(Throwable x)
Callback invoked when the operation fails.
|
static Callback |
from(Callback callback,
Runnable completed)
Create a nested callback that runs completed after
completing the nested callback.
|
static Callback |
from(CompletableFuture<?> completable)
Creates a non-blocking callback from the given incomplete CompletableFuture.
|
static Callback |
from(CompletableFuture<?> completable,
Invocable.InvocationType invocation)
Creates a callback from the given incomplete CompletableFuture,
with the given
blocking characteristic. |
static Callback |
from(Runnable completed)
Creaste a callback that runs completed when it succeeds or fails
|
static Callback |
from(Runnable completed,
Callback callback)
Create a nested callback that runs completed before
completing the nested callback.
|
static Callback |
from(Runnable success,
Consumer<Throwable> failure)
Create a callback from the passed success and failure
|
default void |
succeeded()
Callback invoked when the operation completes.
|
combine, getInvocationType, getInvocationType, invokeNonBlocking, isNonBlockingInvocation
static final Callback NOOP
default void succeeded()
Callback invoked when the operation completes.
failed(Throwable)
default void failed(Throwable x)
Callback invoked when the operation fails.
x
- the reason for the operation failurestatic Callback from(CompletableFuture<?> completable)
Creates a non-blocking callback from the given incomplete CompletableFuture.
When the callback completes, either succeeding or failing, the
CompletableFuture is also completed, respectively via
CompletableFuture.complete(Object)
or
CompletableFuture.completeExceptionally(Throwable)
.
completable
- the CompletableFuture to convert into a callbackstatic Callback from(CompletableFuture<?> completable, Invocable.InvocationType invocation)
Creates a callback from the given incomplete CompletableFuture,
with the given blocking
characteristic.
completable
- the CompletableFuture to convert into a callbackinvocation
- whether the callback is blockingstatic Callback from(Runnable success, Consumer<Throwable> failure)
success
- Called when the callback succeedsfailure
- Called when the callback failsstatic Callback from(Runnable completed)
completed
- The completion to run on success or failurestatic Callback from(Callback callback, Runnable completed)
callback
- The nested callbackcompleted
- The completion to run after the nested callback is completedstatic Callback from(Runnable completed, Callback callback)
callback
- The nested callbackcompleted
- The completion to run before the nested callback is completed. Any exceptions thrown
from completed will result in a callback failure.Copyright © 2010 - 2020 Adobe. All Rights Reserved