public final class Promises extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Promises.Callback<A>
A callback that can be completed with a successful value or a failed
exception.
|
static interface |
Promises.SettablePromise<A>
A promise that can be completed with a successful value or a failed
exception.
|
| Modifier and Type | Method and Description |
|---|---|
static <A> Promise.TryConsumer<A> |
compose(Consumer<? super A> success,
Consumer<Throwable> failure)
Create a
Promise.TryConsumer by composing two Consumer. |
static <A> Promise<A> |
forCompletionStage(CompletionStage<A> stage)
Create a promise from the input completion stage.
|
static <A> Promise<A> |
forCompletionStage(CompletionStage<A> stage,
Optional<Executor> executor)
Create a promise from the input completion stage.
|
static <A> Promise<A> |
forFuture(Future<A> future,
Executor executor)
Creates a promise from the given future.
|
static <A> Promise<A> |
promise(A value)
Creates a new, resolved promise for the specified concrete value.
|
static <A> Promise<A> |
rejected(Throwable t)
Creates a new, rejected promise from the given
Throwable
and result type. |
static <A> Promises.SettablePromise<A> |
settablePromise()
Create a promise for the input effect.
|
static <A> Promises.SettablePromise<A> |
settablePromise(Optional<Executor> executor) |
static <B,A extends B> |
toCompletableFuture(Promise<A> promise)
Return a completable future based on the input promise
|
static <A> Function<A,Promise<A>> |
toPromise()
Deprecated.
use
promise(Object) as a method reference. |
static <A> Promise<List<A>> |
when(Iterable<? extends Promise<? extends A>> promises)
Returns a new
Promise representing the
status of a list of other promises. |
static <A> Promise<List<A>> |
when(Promise<? extends A>... promises)
Returns a new
Promise representing the
status of a list of other promises. |
static <A> Promise<List<A>> |
when(Stream<? extends Promise<? extends A>> promises)
Returns a new
Promise representing the
status of a stream of other promises. |
public static <A> Promises.SettablePromise<A> settablePromise()
A - type of the successful value.Promises.SettablePromise that can be fulfilled by calling the
Promises.Callback methods it implements. Cancelling this Promise will have
no consequence on the code that calls the callback.public static <A> Promises.SettablePromise<A> settablePromise(@Nonnull Optional<Executor> executor)
A - type of the successful value.executor - to be called to run callbacks and transformations attached
to the returned Promise. If None, they will be executed on the caller
thread.Promises.SettablePromise that can be fulfilled by calling the
Promises.Callback methods it implements. Cancelling this Promise will have
no consequence on the code that calls the callback.public static <A> Promise<A> forCompletionStage(@Nonnull CompletionStage<A> stage)
A - type of the successful value.stage - a CompletionStage used as the
precedent of the returned Promise.Promise that will be
fulfilled with the same result that the CompletionStage has. If it
implements
CompletionStage.toCompletableFuture() then
cancelling this Promise will cancel that CompletableFuture.public static <A> Promise<A> forCompletionStage(@Nonnull CompletionStage<A> stage, @Nonnull Optional<Executor> executor)
A - type of the successful value.stage - a CompletionStage used as the
precedent of the returned Promise.executor - to be called to run callbacks and transformations attached
to the returned Promise. If None, they will be executed on the caller
thread.Promise that will be
fulfilled with the same result that the CompletionStage has. If it
implements
CompletionStage.toCompletableFuture() then
cancelling this Promise will cancel that CompletableFuture.public static <B,A extends B> CompletableFuture<B> toCompletableFuture(@Nonnull Promise<A> promise)
B - any super type of A that may be inferred.promise - a Promise used as the
precedent of the returned CompletableFuture.CompletableFuture that will be
fulfilled with the same result that the Promise has.@SafeVarargs public static <A> Promise<List<A>> when(@Nonnull Promise<? extends A>... promises)
Promise representing the
status of a list of other promises.A - an A.promises - The promises that the new promise should trackpublic static <A> Promise<List<A>> when(@Nonnull Iterable<? extends Promise<? extends A>> promises)
Promise representing the
status of a list of other promises. More generally this is known as
{code}sequence{code} as both List and Promise are traversable monads.A - an A.promises - The promises that the new promise should trackpublic static <A> Promise<List<A>> when(@Nonnull Stream<? extends Promise<? extends A>> promises)
Promise representing the
status of a stream of other promises.A - an A.promises - The promises that the new promise should track@Deprecated public static <A> Function<A,Promise<A>> toPromise()
promise(Object) as a method reference.public static <A> Promise<A> promise(A value)
A - an A.value - The value for which a promise should be createdpublic static <A> Promise<A> rejected(@Nonnull Throwable t)
Throwable
and result type.A - an A.t - The throwablepublic static <A> Promise<A> forFuture(@Nonnull Future<A> future, @Nonnull Executor executor)
A - possible future value typefuture - The future delegate for the new promiseexecutor - an executor where a task will run that waits for the future
to completepublic static <A> Promise.TryConsumer<A> compose(@Nonnull Consumer<? super A> success, @Nonnull Consumer<Throwable> failure)
Promise.TryConsumer by composing two Consumer.A - an A.success - To run if the Future is successfulfailure - To run if the Future failsCopyright © 2016 Atlassian. All rights reserved.