Interface Promise<C>
- Type Parameters:
C
- the type of the promise result
- All Known Subinterfaces:
Blocker.Promise<C>
,Promise.Invocable<R>
- All Known Implementing Classes:
FuturePromise
,Promise.Completable
,Promise.Invocable.Abstract
,Promise.Invocable.NonBlocking
,Promise.Task
,Promise.Wrapper
public interface Promise<C>
An abstraction for a completed/failed result of an asynchronous operation.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
A CompletableFuture that is also a Promise.static interface
static class
static class
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> void
completeWith
(Promise<T> promise, CompletableFuture<T> completable) Completes the given promise with the givenCompletableFuture
.default void
Callback method to invoke when the operation fails.static <T> Promise
<T> Creates a promise that runs the givenRunnable
when it succeeds or fails.static <T> Promise
<T> from
(CompletableFuture<? super T> completable) Creates a promise from the given incomplete CompletableFuture.static <T> Promise
<T> Creates a Promise from the given success and failure consumers.static <T> Promise
<T> noop()
default void
Callback method to invoke when the operation succeeds.
-
Method Details
-
succeeded
Callback method to invoke when the operation succeeds.
- Parameters:
result
- the operation result- See Also:
-
failed
Callback method to invoke when the operation fails.
- Parameters:
x
- the operation failure
-
noop
- Type Parameters:
T
- the type of the promise result- Returns:
- a promise that performs no operations.
-
completeWith
Completes the given promise with the given
CompletableFuture
.When the CompletableFuture completes normally, the given promise is succeeded; when the CompletableFuture completes exceptionally, the given promise is failed.
- Parameters:
promise
- the promise to completecompletable
- theCompletableFuture
that completes the 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
-