91 lines
2.8 KiB
Java
91 lines
2.8 KiB
Java
package retrofit2.adapter.rxjava2;
|
|
|
|
import io.reactivex.Observable;
|
|
import io.reactivex.Observer;
|
|
import io.reactivex.disposables.Disposable;
|
|
import io.reactivex.exceptions.CompositeException;
|
|
import io.reactivex.exceptions.Exceptions;
|
|
import io.reactivex.plugins.RxJavaPlugins;
|
|
import retrofit2.Call;
|
|
import retrofit2.Callback;
|
|
import retrofit2.Response;
|
|
|
|
/* loaded from: classes2.dex */
|
|
final class CallEnqueueObservable<T> extends Observable<Response<T>> {
|
|
private final Call<T> originalCall;
|
|
|
|
private static final class CallCallback<T> implements Disposable, Callback<T> {
|
|
private final Call<?> call;
|
|
private final Observer<? super Response<T>> observer;
|
|
boolean terminated = false;
|
|
|
|
CallCallback(Call<?> call, Observer<? super Response<T>> observer) {
|
|
this.call = call;
|
|
this.observer = observer;
|
|
}
|
|
|
|
@Override // io.reactivex.disposables.Disposable
|
|
public void dispose() {
|
|
this.call.cancel();
|
|
}
|
|
|
|
public boolean isDisposed() {
|
|
return this.call.isCanceled();
|
|
}
|
|
|
|
@Override // retrofit2.Callback
|
|
public void onFailure(Call<T> call, Throwable th) {
|
|
if (call.isCanceled()) {
|
|
return;
|
|
}
|
|
try {
|
|
this.observer.onError(th);
|
|
} catch (Throwable th2) {
|
|
Exceptions.b(th2);
|
|
RxJavaPlugins.b(new CompositeException(th, th2));
|
|
}
|
|
}
|
|
|
|
@Override // retrofit2.Callback
|
|
public void onResponse(Call<T> call, Response<T> response) {
|
|
if (call.isCanceled()) {
|
|
return;
|
|
}
|
|
try {
|
|
this.observer.onNext(response);
|
|
if (call.isCanceled()) {
|
|
return;
|
|
}
|
|
this.terminated = true;
|
|
this.observer.onComplete();
|
|
} catch (Throwable th) {
|
|
if (this.terminated) {
|
|
RxJavaPlugins.b(th);
|
|
return;
|
|
}
|
|
if (call.isCanceled()) {
|
|
return;
|
|
}
|
|
try {
|
|
this.observer.onError(th);
|
|
} catch (Throwable th2) {
|
|
Exceptions.b(th2);
|
|
RxJavaPlugins.b(new CompositeException(th, th2));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
CallEnqueueObservable(Call<T> call) {
|
|
this.originalCall = call;
|
|
}
|
|
|
|
@Override // io.reactivex.Observable
|
|
protected void subscribeActual(Observer<? super Response<T>> observer) {
|
|
Call<T> clone = this.originalCall.clone();
|
|
CallCallback callCallback = new CallCallback(clone, observer);
|
|
observer.onSubscribe(callCallback);
|
|
clone.enqueue(callCallback);
|
|
}
|
|
}
|