org.zodiac.reactor.context.ReactorContextUtil Maven / Gradle / Ivy
The newest version!
package org.zodiac.reactor.context;
import java.util.function.Consumer;
import java.util.function.Function;
import org.zodiac.sdk.toolkit.context.Context;
import org.zodiac.sdk.toolkit.context.ContextUtil;
import reactor.core.publisher.Mono;
public abstract class ReactorContextUtil extends ContextUtil {
private ReactorContextUtil() {
}
public static Mono reactiveContext() {
return Mono
.subscriberContext()
.handle((context, sink) -> {
if (context.hasKey(Context.class)) {
sink.next(context.get(Context.class));
} else {
sink.complete();
}
})
.subscriberContext(acceptContext(ctx -> {
}));
}
public static Function acceptContext(Consumer contextConsumer) {
return context -> {
if (!context.hasKey(Context.class)) {
context = context.put(Context.class, createContext());
}
contextConsumer.accept(context.get(Context.class));
return context;
};
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy