From 8a9caf2f497ba1a9b0fa67ac648da9c621f53885 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sat, 18 May 2024 21:35:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20`CffuFactory`=20use=20`new0()`=20in?= =?UTF-8?q?stead=20of=20`dummy()`,=20less=20instance=20creation=20and=20de?= =?UTF-8?q?legation=20=E2=9A=A1=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/foldright/cffu/CffuFactory.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java index 31acaf03..2f30491c 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java @@ -157,14 +157,6 @@ public CompletionStage failedStage(Throwable ex) { // - supplyAsync* //////////////////////////////////////////////////////////////////////////////// - /** - * a completed Cffu with the value {@code null} - */ - @Contract(pure = true) - private Cffu dummy() { - return completedFuture(null); - } - /** * Returns a new Cffu that is asynchronously completed by a task running * in the {@link #defaultExecutor()} after it runs the given action. @@ -174,7 +166,7 @@ private Cffu dummy() { * @see CompletableFuture#runAsync(Runnable) */ public Cffu runAsync(Runnable action) { - return dummy().thenRunAsync(action); + return runAsync(action, defaultExecutor); } /** @@ -187,7 +179,7 @@ public Cffu runAsync(Runnable action) { * @see CompletableFuture#runAsync(Runnable, Executor) */ public Cffu runAsync(Runnable action, Executor executor) { - return dummy().thenRunAsync(action, executor); + return new0(CompletableFuture.runAsync(action, executor)); } /** @@ -203,7 +195,7 @@ public Cffu runAsync(Runnable action, Executor executor) { @CheckReturnValue(explanation = "should use the returned Cffu; otherwise, prefer method `runAsync`") @SuppressWarnings("BoundedWildcard") public Cffu supplyAsync(Supplier supplier) { - return dummy().thenApplyAsync(unused -> supplier.get()); + return supplyAsync(supplier, defaultExecutor); } /** @@ -219,7 +211,7 @@ public Cffu supplyAsync(Supplier supplier) { @CheckReturnValue(explanation = "should use the returned Cffu; otherwise, prefer method `runAsync`") @SuppressWarnings("BoundedWildcard") public Cffu supplyAsync(Supplier supplier, Executor executor) { - return dummy().thenApplyAsync(unused -> supplier.get(), executor); + return new0(CompletableFuture.supplyAsync(supplier, executor)); } ////////////////////////////////////////////////////////////////////////////////