From ed817b9ea0c03365989af3ce458f2be57ef4e85f Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sun, 2 Jun 2024 20:01:22 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20use=20`cffuCompleteOnTimeout`=20instead?= =?UTF-8?q?=20of=20`cffuOrTimeout`=20in=20`mostOf*`=20methods=20for=20mult?= =?UTF-8?q?iply=20input=20cfs=20=E2=9A=A1=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `cffuCompleteOnTimeout` won't create `TimeoutException` --- .../java/io/foldright/cffu/CompletableFutureUtils.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 8049dcfd..70223e9b 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java @@ -254,7 +254,7 @@ public static CompletableFuture> mostResultsOfSuccess( // MUST be non-minimal-stage CF instances in order to read results(`getSuccessNow`), // otherwise UnsupportedOperationException final CompletableFuture[] cfArray = f_toNonMinCfArray(cfs); - return cffuOrTimeout(CompletableFuture.allOf(cfArray), executorWhenTimeout, timeout, unit) + return cffuCompleteOnTimeout(CompletableFuture.allOf(cfArray), null, executorWhenTimeout, timeout, unit) .handle((unused, ex) -> arrayList(MGetSuccessNow0(valueIfNotSuccess, cfArray))); } @@ -800,7 +800,7 @@ private static CompletableFuture mostTupleOfSuccess0( // MUST be *Non-Minimal* CF instances in order to read results(`getSuccessNow`), // otherwise UnsupportedOperationException final CompletableFuture[] cfArray = f_toNonMinCfArray(css); - return cffuOrTimeout(CompletableFuture.allOf(cfArray), executorWhenTimeout, timeout, unit) + return cffuCompleteOnTimeout(CompletableFuture.allOf(cfArray), null, executorWhenTimeout, timeout, unit) .handle((unused, ex) -> tupleOf0(MGetSuccessNow0(null, cfArray))); } @@ -1513,8 +1513,7 @@ public static > C cffuOrTimeout( requireNonNull(executorWhenTimeout, "executorWhenTimeout is null"); requireNonNull(unit, "unit is null"); - final C f = orTimeout(cf, timeout, unit); - return hopExecutorIfAtCfDelayerThread(f, executorWhenTimeout); + return hopExecutorIfAtCfDelayerThread(orTimeout(cf, timeout, unit), executorWhenTimeout); } /** @@ -1589,8 +1588,7 @@ C cffuCompleteOnTimeout(C cf, @Nullable T value, Executor executorWhenTimeout, l requireNonNull(executorWhenTimeout, "executorWhenTimeout is null"); requireNonNull(unit, "unit is null"); - final C f = completeOnTimeout(cf, value, timeout, unit); - return hopExecutorIfAtCfDelayerThread(f, executorWhenTimeout); + return hopExecutorIfAtCfDelayerThread(completeOnTimeout(cf, value, timeout, unit), executorWhenTimeout); } /**