Interface Promise<C>
- Type Parameters:
C- the type of the context object
- All Known Subinterfaces:
Blocker.Promise<C>, Promise.Invocable<R>
- All Known Implementing Classes:
FuturePromise, Promise.Adapter, Promise.Completable, Promise.Task, Promise.Wrapper
public interface Promise<C>
A callback abstraction that handles completed/failed events of asynchronous operations.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classEmpty implementation ofPromise.static classA CompletableFuture that is also a Promise.static interfacestatic classstatic class -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault voidcompleteWith(CompletableFuture<C> completable) Completes this promise with the givenCompletableFuture.default voidCallback invoked when the operation fails.static <T> Promise<T> Creates a promise that runs the givenRunnablewhen it succeeds or fails.static <T> Promise<T> from(CompletableFuture<? super T> completable) Creates a promise from the given incomplete CompletableFuture.static <C> Promise.Invocable<C> Create anPromise.Invocablethat isInvocable.InvocationType.NON_BLOCKINGbecause it executes the callbacksstatic <T> Promise<T> Creates a Promise from the given success and failure consumers.static <C> Promise.Invocable<C> from(Invocable.InvocationType invocationType, Promise<C> promise) Create anPromise.Invocablestatic <T> Promise<T> noop()default voidCallback invoked when the operation completes.
-
Field Details
-
NOOP
-
-
Method Details
-
noop
-
succeeded
Callback invoked when the operation completes.
- Parameters:
result- the context- See Also:
-
failed
Callback invoked when the operation fails.
- Parameters:
x- the reason for the operation failure
-
completeWith
Completes this promise with the given
CompletableFuture.When the CompletableFuture completes normally, this promise is succeeded; when the CompletableFuture completes exceptionally, this promise is failed.
- Parameters:
completable- the CompletableFuture that completes this promise
-
from
Creates a Promise from the given success and failure consumers.
- Type Parameters:
T- the type of the result- Parameters:
success- the consumer invoked when the promise is succeededfailure- the consumer invoked when the promise is failed- Returns:
- a new Promise wrapping the success and failure consumers.
-
from
Creates a promise from the given incomplete CompletableFuture.
When the promise completes, either succeeding or failing, the CompletableFuture is also completed, respectively via
CompletableFuture.complete(Object)orCompletableFuture.completeExceptionally(Throwable).- Type Parameters:
T- the type of the result- Parameters:
completable- the CompletableFuture to convert into a promise- Returns:
- a promise that when completed, completes the given CompletableFuture
-
from
-
from
Create anPromise.Invocable- Type Parameters:
C- The type- Parameters:
invocationType- TheInvocable.InvocationTypeof calls to thePromise.Invocablepromise- The promise on which to delegate calls to.- Returns:
- An
InvocablePromise.
-
from
Create anPromise.Invocablethat isInvocable.InvocationType.NON_BLOCKINGbecause it executes the callbacks
-