io.smallrye.faulttolerance.rxjava3.impl.MaybeSupport Maven / Gradle / Ivy
package io.smallrye.faulttolerance.rxjava3.impl;
import java.util.concurrent.CompletionStage;
import io.reactivex.rxjava3.core.Maybe;
import io.smallrye.faulttolerance.core.invocation.AsyncSupport;
import io.smallrye.faulttolerance.core.invocation.Invoker;
public class MaybeSupport implements AsyncSupport> {
@Override
public String mustDescription() {
return "return " + Maybe.class.getSimpleName();
}
@Override
public String doesDescription() {
return "returns " + Maybe.class.getSimpleName();
}
@Override
public boolean applies(Class>[] parameterTypes, Class> returnType) {
return Maybe.class.equals(returnType);
}
@Override
public Maybe createComplete(T value) {
return Maybe.just(value);
}
@Override
public CompletionStage toCompletionStage(Invoker> invoker) throws Exception {
return invoker.proceed().toCompletionStage(null);
}
@Override
public Maybe fromCompletionStage(Invoker> invoker) {
return Maybe.defer(() -> Maybe.fromCompletionStage(invoker.proceed()));
}
@Override
public CompletionStage fallbackResultToCompletionStage(Maybe maybe) {
return maybe.toCompletionStage(null);
}
}