From 30fbd128e2ed82e6b4e1da7f238f2d230d712aa0 Mon Sep 17 00:00:00 2001 From: Julien Ponge Date: Sat, 18 Jun 2022 10:35:21 +0200 Subject: [PATCH] Add missing decoration of Callable --- .../context/BaseContextPropagationInterceptor.java | 10 ++++++++++ .../mutiny/infrastructure/CallbackDecorator.java | 14 +++++++++++++- .../mutiny/infrastructure/Infrastructure.java | 8 ++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/context-propagation/src/main/java/io/smallrye/mutiny/context/BaseContextPropagationInterceptor.java b/context-propagation/src/main/java/io/smallrye/mutiny/context/BaseContextPropagationInterceptor.java index f1f84c465..2db500dda 100644 --- a/context-propagation/src/main/java/io/smallrye/mutiny/context/BaseContextPropagationInterceptor.java +++ b/context-propagation/src/main/java/io/smallrye/mutiny/context/BaseContextPropagationInterceptor.java @@ -1,5 +1,6 @@ package io.smallrye.mutiny.context; +import java.util.concurrent.Callable; import java.util.concurrent.Executor; import java.util.function.*; @@ -68,6 +69,15 @@ public Runnable decorate(Runnable runnable) { return context.contextualRunnable(runnable); } + @Override + public Callable decorate(Callable callable) { + SmallRyeThreadContext context = getThreadContext(); + if (context.isContextualized(callable)) { + return callable; + } + return context.contextualCallable(callable); + } + @Override public BiConsumer decorate(BiConsumer consumer) { SmallRyeThreadContext context = getThreadContext(); diff --git a/implementation/src/main/java/io/smallrye/mutiny/infrastructure/CallbackDecorator.java b/implementation/src/main/java/io/smallrye/mutiny/infrastructure/CallbackDecorator.java index 2aa05ee16..8d97cb46f 100644 --- a/implementation/src/main/java/io/smallrye/mutiny/infrastructure/CallbackDecorator.java +++ b/implementation/src/main/java/io/smallrye/mutiny/infrastructure/CallbackDecorator.java @@ -1,5 +1,6 @@ package io.smallrye.mutiny.infrastructure; +import java.util.concurrent.Callable; import java.util.function.*; import io.smallrye.mutiny.tuples.Functions; @@ -8,7 +9,7 @@ * Intercept user callbacks. * Decorators are called when the user passes a callback to Mutiny and so decorators can modify the passed callback. *

- * The default behavior is to returns the user's callback, unchanged. + * The default behavior is to return the user's callback, unchanged. *

* Decorators must not transform a user callback into {@code null}. */ @@ -56,6 +57,17 @@ default Runnable decorate(Runnable runnable) { return runnable; } + /** + * Allows decorating a {@link Callable}. + * + * @param callable the callable + * @return the decorated callable + * @param the callable return type + */ + default Callable decorate(Callable callable) { + return callable; + } + /** * Allows decorating a {@link BiConsumer}. * diff --git a/implementation/src/main/java/io/smallrye/mutiny/infrastructure/Infrastructure.java b/implementation/src/main/java/io/smallrye/mutiny/infrastructure/Infrastructure.java index e1318d92b..a737462ba 100644 --- a/implementation/src/main/java/io/smallrye/mutiny/infrastructure/Infrastructure.java +++ b/implementation/src/main/java/io/smallrye/mutiny/infrastructure/Infrastructure.java @@ -153,6 +153,14 @@ public static Runnable decorate(Runnable runnable) { return current; } + public static Callable decorate(Callable callable) { + Callable current = callable; + for (CallbackDecorator interceptor : CALLBACK_DECORATORS) { + current = interceptor.decorate(current); + } + return current; + } + public static BiConsumer decorate(BiConsumer consumer) { BiConsumer current = consumer; for (CallbackDecorator interceptor : CALLBACK_DECORATORS) {