From a72bdce58323477ac8706f39f943980636969268 Mon Sep 17 00:00:00 2001 From: chexing Date: Tue, 25 Jul 2023 16:56:10 +0800 Subject: [PATCH 1/2] bugfix-[supplyAsyncWithCurrentScope can't pass current Scope] --- .../java/com/github/phantomthief/scope/ScopeUtils.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/phantomthief/scope/ScopeUtils.java b/src/main/java/com/github/phantomthief/scope/ScopeUtils.java index 903392e..fb0e7a4 100644 --- a/src/main/java/com/github/phantomthief/scope/ScopeUtils.java +++ b/src/main/java/com/github/phantomthief/scope/ScopeUtils.java @@ -14,6 +14,7 @@ import java.time.Duration; import java.util.Iterator; import java.util.Map.Entry; +import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; @@ -69,6 +70,10 @@ private static Supplier wrapSupplierExistScope(@Nullable Scope scope, @Nonnull Supplier supplier) { return () -> supplyWithExistScope(scope, supplier::get); } + private static Callable wrapCallableExistScope(@Nullable Scope scope, + @Nonnull Supplier supplier) { + return () -> supplyWithExistScope(scope, supplier::get); + } public static void runAsyncWithCurrentScope(@Nonnull Runnable runnable, @Nonnull Executor executor) { @@ -84,13 +89,13 @@ public static ListenableFuture runAsyncWithCurrentScope(@Nonnull Runnable run @Nonnull public static Future supplyAsyncWithCurrentScope(@Nonnull Supplier supplier, @Nonnull ExecutorService executor) { - return executor.submit(() -> wrapSupplierExistScope(getCurrentScope(), supplier).get()); + return executor.submit(wrapCallableExistScope(getCurrentScope(), supplier)); } @Nonnull public static ListenableFuture supplyAsyncWithCurrentScope(@Nonnull Supplier supplier, @Nonnull ListeningExecutorService executor) { - return executor.submit(() -> wrapSupplierExistScope(getCurrentScope(), supplier).get()); + return executor.submit(wrapCallableExistScope(getCurrentScope(), supplier)); } /** From fa742266897da6401bce436037cbf33e65464b54 Mon Sep 17 00:00:00 2001 From: JuJuXC Date: Tue, 8 Aug 2023 21:57:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/github/phantomthief/scope/ScopeUtils.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/github/phantomthief/scope/ScopeUtils.java b/src/main/java/com/github/phantomthief/scope/ScopeUtils.java index fb0e7a4..8538e3d 100644 --- a/src/main/java/com/github/phantomthief/scope/ScopeUtils.java +++ b/src/main/java/com/github/phantomthief/scope/ScopeUtils.java @@ -70,6 +70,14 @@ private static Supplier wrapSupplierExistScope(@Nullable Scope scope, @Nonnull Supplier supplier) { return () -> supplyWithExistScope(scope, supplier::get); } + + /** + * 入参顺序调整,传入scope进入新线程 + * @param scope + * @param supplier + * @return + * @param + */ private static Callable wrapCallableExistScope(@Nullable Scope scope, @Nonnull Supplier supplier) { return () -> supplyWithExistScope(scope, supplier::get);