Skip to content

Commit

Permalink
fix: add missing MinimalStage check for Cffu#getSuccessNow() method…
Browse files Browse the repository at this point in the history
… 👀change `getSuccessNow` method parameter type to `CompletableFuture` from `CompletionStage` ⚠️
  • Loading branch information
oldratlee committed May 23, 2024
1 parent 0f18ed5 commit 61125ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions cffu-core/src/main/java/io/foldright/cffu/Cffu.java
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,7 @@ public T getNow(T valueIfAbsent) {
@Contract(pure = true)
@Nullable
public T getSuccessNow(@Nullable T valueIfNotSuccess) {
checkMinimalStage();
return CompletableFutureUtils.getSuccessNow(cf, valueIfNotSuccess);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ public static <T> CompletableFuture<List<T>> allResultsOfFastFail(CompletionStag
* the given stages in the given time({@code timeout}), aka as many results as possible in the given time.
* <p>
* If the given stage is successful, its result is the completed value; Otherwise the given valueIfNotSuccess.
* (aka the result extraction logic is {@link #getSuccessNow(CompletionStage, Object)}).
* (aka the result extraction logic is {@link #getSuccessNow(CompletableFuture, Object)}).
*
* @param timeout how long to wait in units of {@code unit}
* @param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter
* @param valueIfNotSuccess the value to return if not completed successfully
* @param cfs the stages
* @see #getSuccessNow(CompletionStage, Object)
* @see #getSuccessNow(CompletableFuture, Object)
*/
// * @see #MGetSuccessNow(Object, CompletionStage[])
@Contract(pure = true)
Expand Down Expand Up @@ -1346,9 +1346,8 @@ public static <T> T join(CompletableFuture<T> cf, long timeout, TimeUnit unit) {
// * @see #MGetSuccessNow(Object, CompletionStage[])
@Contract(pure = true)
@Nullable
public static <T> T getSuccessNow(CompletionStage<? extends T> cf, @Nullable T valueIfNotSuccess) {
final CompletableFuture<T> f = toCf(cf);
return f.isDone() && !f.isCompletedExceptionally() ? f.join() : valueIfNotSuccess;
public static <T> T getSuccessNow(CompletableFuture<? extends T> cf, @Nullable T valueIfNotSuccess) {
return cf.isDone() && !cf.isCompletedExceptionally() ? cf.join() : valueIfNotSuccess;
}

/**
Expand Down Expand Up @@ -1473,11 +1472,11 @@ public static CffuState state(CompletableFuture<?> cf) {
/**
* Multi-Gets(MGet) the results in the <strong>same order</strong> of the given cfs,
* use the result value if the given stage is completed successfully, else use the given valueIfNotSuccess
* (aka the result extraction logic is {@link #getSuccessNow(CompletionStage, Object)}).
* (aka the result extraction logic is {@link #getSuccessNow(CompletableFuture, Object)}).
*
* @param cfs the stages
* @see #mostResultsOfSuccess(long, TimeUnit, Object, CompletionStage[])
* @see #getSuccessNow(CompletionStage, Object)
* @see #getSuccessNow(CompletableFuture, Object)
*/
@Contract(pure = true)
@SafeVarargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ fun <T> CompletableFuture<T>.join(timeout: Long, unit: TimeUnit): T =
* @return the result value, if completed successfully, else the given valueIfNotSuccess
*/
@Suppress("UNCHECKED_CAST")
fun <T> CompletionStage<T>.getSuccessNow(valueIfNotSuccess: T): T =
fun <T> CompletableFuture<T>.getSuccessNow(valueIfNotSuccess: T): T =
CompletableFutureUtils.getSuccessNow(this, valueIfNotSuccess) as T

/**
Expand Down

0 comments on commit 61125ed

Please sign in to comment.