From ad30d587953f0c3ad0e2363d9a930c892ad227f1 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sat, 18 May 2024 20:11:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20add=20missing=20MinimalStage=20check=20f?= =?UTF-8?q?or=20`Cffu#getSuccessNow()`=20method=20=F0=9F=91=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cffu-core/src/main/java/io/foldright/cffu/Cffu.java | 1 + .../io/foldright/cffu/CompletableFutureUtils.java | 13 ++++++------- .../cffu/kotlin/CompletableFutureExtensions.kt | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cffu-core/src/main/java/io/foldright/cffu/Cffu.java b/cffu-core/src/main/java/io/foldright/cffu/Cffu.java index 6bcaf42e..8a672324 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/Cffu.java +++ b/cffu-core/src/main/java/io/foldright/cffu/Cffu.java @@ -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); } diff --git a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java index 313864b6..79ca16ae 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java @@ -190,13 +190,13 @@ public static CompletableFuture> allResultsOfFastFail(CompletionStag * the given stages in the given time({@code timeout}), aka as many results as possible in the given time. *

* 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) @@ -1346,9 +1346,8 @@ public static T join(CompletableFuture cf, long timeout, TimeUnit unit) { // * @see #MGetSuccessNow(Object, CompletionStage[]) @Contract(pure = true) @Nullable - public static T getSuccessNow(CompletionStage cf, @Nullable T valueIfNotSuccess) { - final CompletableFuture f = toCf(cf); - return f.isDone() && !f.isCompletedExceptionally() ? f.join() : valueIfNotSuccess; + public static T getSuccessNow(CompletableFuture cf, @Nullable T valueIfNotSuccess) { + return cf.isDone() && !cf.isCompletedExceptionally() ? cf.join() : valueIfNotSuccess; } /** @@ -1473,11 +1472,11 @@ public static CffuState state(CompletableFuture cf) { /** * Multi-Gets(MGet) the results in the same order 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 diff --git a/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CompletableFutureExtensions.kt b/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CompletableFutureExtensions.kt index 5d4c2940..f4b33ef6 100644 --- a/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CompletableFutureExtensions.kt +++ b/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CompletableFutureExtensions.kt @@ -1011,7 +1011,7 @@ fun CompletableFuture.join(timeout: Long, unit: TimeUnit): T = * @return the result value, if completed successfully, else the given valueIfNotSuccess */ @Suppress("UNCHECKED_CAST") -fun CompletionStage.getSuccessNow(valueIfNotSuccess: T): T = +fun CompletableFuture.getSuccessNow(valueIfNotSuccess: T): T = CompletableFutureUtils.getSuccessNow(this, valueIfNotSuccess) as T /**