use of io.reactivex.rxjava3.core.Maybe in project retrofit by square.
the class RxJava3CallAdapterFactory method get.
@Override
@Nullable
public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) {
Class<?> rawType = getRawType(returnType);
if (rawType == Completable.class) {
// can only be created with a single configuration.
return new RxJava3CallAdapter(Void.class, scheduler, isAsync, false, true, false, false, false, true);
}
boolean isFlowable = rawType == Flowable.class;
boolean isSingle = rawType == Single.class;
boolean isMaybe = rawType == Maybe.class;
if (rawType != Observable.class && !isFlowable && !isSingle && !isMaybe) {
return null;
}
boolean isResult = false;
boolean isBody = false;
Type responseType;
if (!(returnType instanceof ParameterizedType)) {
String name = isFlowable ? "Flowable" : isSingle ? "Single" : isMaybe ? "Maybe" : "Observable";
throw new IllegalStateException(name + " return type must be parameterized" + " as " + name + "<Foo> or " + name + "<? extends Foo>");
}
Type observableType = getParameterUpperBound(0, (ParameterizedType) returnType);
Class<?> rawObservableType = getRawType(observableType);
if (rawObservableType == Response.class) {
if (!(observableType instanceof ParameterizedType)) {
throw new IllegalStateException("Response must be parameterized" + " as Response<Foo> or Response<? extends Foo>");
}
responseType = getParameterUpperBound(0, (ParameterizedType) observableType);
} else if (rawObservableType == Result.class) {
if (!(observableType instanceof ParameterizedType)) {
throw new IllegalStateException("Result must be parameterized" + " as Result<Foo> or Result<? extends Foo>");
}
responseType = getParameterUpperBound(0, (ParameterizedType) observableType);
isResult = true;
} else {
responseType = observableType;
isBody = true;
}
return new RxJava3CallAdapter(responseType, scheduler, isAsync, isResult, isBody, isFlowable, isSingle, isMaybe, false);
}
use of io.reactivex.rxjava3.core.Maybe in project smallrye-mutiny by smallrye.
the class MultiConvertFromTest method testCreatingFromAMaybeNeverEmitting.
@Test
public void testCreatingFromAMaybeNeverEmitting() {
AtomicBoolean cancelled = new AtomicBoolean();
Multi<Integer> multi = Multi.createFrom().converter(MultiRx3Converters.fromMaybe(), Maybe.<Integer>never().doOnDispose(() -> cancelled.set(true)));
assertThat(multi).isNotNull();
multi.subscribe().with(i -> {
}).cancel();
assertThat(cancelled).isTrue();
}
use of io.reactivex.rxjava3.core.Maybe in project smallrye-mutiny by smallrye.
the class FromMaybe method from.
@Override
public Uni<T> from(Maybe<T> instance) {
return Uni.createFrom().emitter(sink -> {
Disposable disposable = instance.subscribe(sink::complete, sink::fail, () -> sink.complete(null));
sink.onTermination(() -> {
if (!disposable.isDisposed()) {
disposable.dispose();
}
});
});
}
use of io.reactivex.rxjava3.core.Maybe in project cxf by apache.
the class JAXRSRxJava3MaybeTest method testGetHelloWorldEmpty.
@Test
public void testGetHelloWorldEmpty() throws Exception {
String address = "http://localhost:" + PORT + "/rx3/maybe/empty";
final Flowable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get();
final TestSubscriber<Response> subscriber = new TestSubscriber<>();
obs.subscribe(subscriber);
subscriber.await(3, TimeUnit.SECONDS);
subscriber.assertValue(r -> !r.hasEntity()).assertComplete();
}
use of io.reactivex.rxjava3.core.Maybe in project cxf by apache.
the class JAXRSRxJava3MaybeTest method testGetHelloWorldJson.
@Test
public void testGetHelloWorldJson() throws Exception {
String address = "http://localhost:" + PORT + "/rx3/maybe/textJson";
final Flowable<HelloWorldBean> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get(HelloWorldBean.class);
final TestSubscriber<HelloWorldBean> subscriber = new TestSubscriber<>();
obs.subscribe(subscriber);
subscriber.await(3, TimeUnit.SECONDS);
subscriber.assertValue(r -> "Hello".equals(r.getGreeting()) && "World".equals(r.getAudience())).assertComplete();
}
Aggregations