Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing decoration of Callable<V> #956

Merged
merged 1 commit into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.smallrye.mutiny.context;

import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.function.*;

Expand Down Expand Up @@ -68,6 +69,15 @@ public Runnable decorate(Runnable runnable) {
return context.contextualRunnable(runnable);
}

@Override
public <V> Callable<V> decorate(Callable<V> callable) {
SmallRyeThreadContext context = getThreadContext();
if (context.isContextualized(callable)) {
return callable;
}
return context.contextualCallable(callable);
}

@Override
public <T1, T2> BiConsumer<T1, T2> decorate(BiConsumer<T1, T2> consumer) {
SmallRyeThreadContext context = getThreadContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.smallrye.mutiny.infrastructure;

import java.util.concurrent.Callable;
import java.util.function.*;

import io.smallrye.mutiny.tuples.Functions;
Expand All @@ -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.
* <p>
* The default behavior is to returns the user's callback, unchanged.
* The default behavior is to return the user's callback, unchanged.
* <p>
* Decorators must not transform a user callback into {@code null}.
*/
Expand Down Expand Up @@ -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 <V> the callable return type
*/
default <V> Callable<V> decorate(Callable<V> callable) {
return callable;
}

/**
* Allows decorating a {@link BiConsumer}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ public static Runnable decorate(Runnable runnable) {
return current;
}

public static <V> Callable<V> decorate(Callable<V> callable) {
Callable<V> current = callable;
for (CallbackDecorator interceptor : CALLBACK_DECORATORS) {
current = interceptor.decorate(current);
}
return current;
}

public static <T1, T2> BiConsumer<T1, T2> decorate(BiConsumer<T1, T2> consumer) {
BiConsumer<T1, T2> current = consumer;
for (CallbackDecorator interceptor : CALLBACK_DECORATORS) {
Expand Down