use of com.apollographql.apollo.api.Response in project apollo-android by apollographql.
the class RxApollo method from.
@Nonnull
public static <T> Observable<Response<T>> from(@Nonnull final ApolloSubscriptionCall<T> call, Emitter.BackpressureMode backpressureMode) {
checkNotNull(call, "call == null");
return Observable.create(new Action1<Emitter<Response<T>>>() {
@Override
public void call(final Emitter<Response<T>> emitter) {
final AtomicBoolean canceled = new AtomicBoolean();
emitter.setCancellation(new Cancellable() {
@Override
public void cancel() throws Exception {
canceled.set(true);
call.cancel();
}
});
call.execute(new ApolloSubscriptionCall.Callback<T>() {
@Override
public void onResponse(@Nonnull Response<T> response) {
if (!canceled.get()) {
emitter.onNext(response);
}
}
@Override
public void onFailure(@Nonnull ApolloException e) {
Exceptions.throwIfFatal(e);
if (!canceled.get()) {
emitter.onError(e);
}
}
@Override
public void onCompleted() {
if (!canceled.get()) {
emitter.onCompleted();
}
}
});
}
}, backpressureMode);
}
use of com.apollographql.apollo.api.Response in project RandomWebm by alkocher.
the class ToggleVotesUtil method toggleDislike.
public void toggleDislike(String webmId, boolean hasLike, boolean hasDislike) {
ApolloMutationCall<ToggleDislikeMutation.Data> dislikeMutationCall = WebmApolloClient.getWebmApolloClient().mutate(new ToggleDislikeMutation(webmId, hasLike, hasDislike));
mDisposable.add(Rx2Apollo.from(dislikeMutationCall).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribeWith(new DisposableObserver<Response<ToggleDislikeMutation.Data>>() {
@Override
public void onNext(Response<ToggleDislikeMutation.Data> dataResponse) {
}
@Override
public void onError(Throwable e) {
webmData.showErrorSnackbar();
}
@Override
public void onComplete() {
webmData.showSuccessSnackbar();
}
}));
}
Aggregations