Class CompletableFutures
java.lang.Object
ru.progrm_jarvis.javacommons.util.concurrent.CompletableFutures
Utilities related to
completable futures.-
Method Summary
Modifier and TypeMethodDescriptionstatic <F,S> @NotNull CompletableFuture<@NotNull Pair<F, S>> bothOf(@NonNull CompletableFuture<F> first, @NonNull CompletableFuture<S> second) Returns the completable future whose result is a pair of the provided future's results if both of them complete.static <F,S> @NotNull CompletableFuture<@NotNull Result<F, S>> eitherOf(@NonNull CompletableFuture<F> successFuture, @NonNull CompletableFuture<S> errorFuture) Returns the completable future whose result is the result of either the first or the second future wrapped in either asuccessful resultor anerror resultrespectively.static <@Any T> @NotNull CompletableFuture<T>exceptionallyCompletedFuture(@NonNull Throwable throwable) Creates a completable future which instantlycompletes exceptionallywith the provided throwable.
-
Method Details
-
exceptionallyCompletedFuture
@NotNull public static <@Any T> @NotNull CompletableFuture<T> exceptionallyCompletedFuture(@NonNull @NonNull Throwable throwable) Creates a completable future which instantlycompletes exceptionallywith the provided throwable.- Type Parameters:
T- the result type of the future- Parameters:
throwable- throwable with which the future completes exceptionally- Returns:
- the exceptionally completed future
- Throws:
NullPointerException- ifthrowableisnull
-
bothOf
@NotNull public static <F,S> @NotNull CompletableFuture<@NotNull Pair<F,S>> bothOf(@NonNull @NonNull CompletableFuture<F> first, @NonNull @NonNull CompletableFuture<S> second) Returns the completable future whose result is a pair of the provided future's results if both of them complete. The future completes exceptionally if any of the given futures completes exceptionally.- Type Parameters:
F- the result type of the first futureS- the result type of the second future- Parameters:
first- first futuresecond- second future- Returns:
- a new completable future that is completed when both of the given futures complete
- Throws:
NullPointerException- iffirstisnullNullPointerException- ifsecondisnull- See Also:
-
eitherOf
@NotNull public static <F,S> @NotNull CompletableFuture<@NotNull Result<F,S>> eitherOf(@NonNull @NonNull CompletableFuture<F> successFuture, @NonNull @NonNull CompletableFuture<S> errorFuture) Returns the completable future whose result is the result of either the first or the second future wrapped in either asuccessful resultor anerror resultrespectively. The future completes exceptionally if the first completing future completes exceptionally.- Type Parameters:
F- the result type of the first futureS- the result type of the second future- Parameters:
successFuture- first futureserrorFuture- second futures- Returns:
- a new completable future that is completed when either of the given futures completes
- Throws:
NullPointerException- ifsuccessFutureisnullNullPointerException- iferrorFutureisnull- See Also:
-