趣约 v1.0.0版本的 MD5 值为:39b38c4fdd4abffa44fa3a81ea9918d4
以下内容为反编译后的 SingleLife.java 源代码,内容仅作参考
package com.rxjava.rxlife;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.core.SingleObserver;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.exceptions.Exceptions;
import io.reactivex.rxjava3.functions.BiConsumer;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.internal.functions.Functions;
import io.reactivex.rxjava3.internal.observers.BiConsumerSingleObserver;
import io.reactivex.rxjava3.internal.observers.ConsumerSingleObserver;
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
public class SingleLife<T> extends RxSource<SingleObserver<? super T>> {
private final Single<T> upStream;
@Override
public void subscribe(Object obj) {
subscribe((SingleObserver) ((SingleObserver) obj));
}
@Override
public Object subscribeWith(Object obj) {
return super.subscribeWith(obj);
}
public SingleLife(Single<T> single, Scope scope, boolean z) {
super(scope, z);
this.upStream = single;
}
@Override
public final Disposable subscribe() {
return subscribe(Functions.emptyConsumer(), Functions.ON_ERROR_MISSING);
}
public final Disposable subscribe(Consumer<? super T> consumer) {
return subscribe(consumer, Functions.ON_ERROR_MISSING);
}
public final Disposable subscribe(BiConsumer<? super T, ? super Throwable> biConsumer) {
ObjectHelper.requireNonNull(biConsumer, "onCallback is null");
BiConsumerSingleObserver biConsumerSingleObserver = new BiConsumerSingleObserver(biConsumer);
subscribe((SingleObserver) biConsumerSingleObserver);
return biConsumerSingleObserver;
}
public final Disposable subscribe(Consumer<? super T> consumer, Consumer<? super Throwable> consumer2) {
ObjectHelper.requireNonNull(consumer, "onSuccess is null");
ObjectHelper.requireNonNull(consumer2, "onError is null");
ConsumerSingleObserver consumerSingleObserver = new ConsumerSingleObserver(consumer, consumer2);
subscribe((SingleObserver) consumerSingleObserver);
return consumerSingleObserver;
}
public final void subscribe(SingleObserver<? super T> singleObserver) {
ObjectHelper.requireNonNull(singleObserver, "observer is null");
SingleObserver<? super T> onSubscribe = RxJavaPlugins.onSubscribe(this.upStream, singleObserver);
ObjectHelper.requireNonNull(onSubscribe, "The RxJavaPlugins.onSubscribe hook returned a null SingleObserver. Please check the handler provided to RxJavaPlugins.setOnSingleSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins");
try {
subscribeActual(onSubscribe);
} catch (NullPointerException e) {
throw e;
} catch (Throwable th) {
Exceptions.throwIfFatal(th);
NullPointerException nullPointerException = new NullPointerException("subscribeActual failed");
nullPointerException.initCause(th);
throw nullPointerException;
}
}
private void subscribeActual(SingleObserver<? super T> singleObserver) {
Single<T> single = this.upStream;
if (this.onMain) {
single = single.observeOn(AndroidSchedulers.mainThread());
}
single.onTerminateDetach().subscribe(new LifeSingleObserver(singleObserver, this.scope));
}
}