104 lines
3.1 KiB
Java
104 lines
3.1 KiB
Java
package io.reactivex.internal.operators.observable;
|
|
|
|
import io.reactivex.Observable;
|
|
import io.reactivex.ObservableEmitter;
|
|
import io.reactivex.ObservableOnSubscribe;
|
|
import io.reactivex.Observer;
|
|
import io.reactivex.disposables.Disposable;
|
|
import io.reactivex.exceptions.Exceptions;
|
|
import io.reactivex.internal.disposables.DisposableHelper;
|
|
import io.reactivex.plugins.RxJavaPlugins;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class ObservableCreate<T> extends Observable<T> {
|
|
final ObservableOnSubscribe<T> a;
|
|
|
|
public ObservableCreate(ObservableOnSubscribe<T> observableOnSubscribe) {
|
|
this.a = observableOnSubscribe;
|
|
}
|
|
|
|
@Override // io.reactivex.Observable
|
|
protected void subscribeActual(Observer<? super T> observer) {
|
|
CreateEmitter createEmitter = new CreateEmitter(observer);
|
|
observer.onSubscribe(createEmitter);
|
|
try {
|
|
this.a.subscribe(createEmitter);
|
|
} catch (Throwable th) {
|
|
Exceptions.b(th);
|
|
createEmitter.onError(th);
|
|
}
|
|
}
|
|
|
|
static final class CreateEmitter<T> extends AtomicReference<Disposable> implements ObservableEmitter<T>, Disposable {
|
|
final Observer<? super T> a;
|
|
|
|
CreateEmitter(Observer<? super T> observer) {
|
|
this.a = observer;
|
|
}
|
|
|
|
public boolean a(Throwable th) {
|
|
if (th == null) {
|
|
th = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
|
|
}
|
|
if (a()) {
|
|
return false;
|
|
}
|
|
try {
|
|
this.a.onError(th);
|
|
dispose();
|
|
return true;
|
|
} catch (Throwable th2) {
|
|
dispose();
|
|
throw th2;
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.disposables.Disposable
|
|
public void dispose() {
|
|
DisposableHelper.dispose(this);
|
|
}
|
|
|
|
@Override // io.reactivex.Emitter
|
|
public void onComplete() {
|
|
if (a()) {
|
|
return;
|
|
}
|
|
try {
|
|
this.a.onComplete();
|
|
} finally {
|
|
dispose();
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.Emitter
|
|
public void onError(Throwable th) {
|
|
if (a(th)) {
|
|
return;
|
|
}
|
|
RxJavaPlugins.b(th);
|
|
}
|
|
|
|
@Override // io.reactivex.Emitter
|
|
public void onNext(T t) {
|
|
if (t == null) {
|
|
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
|
|
} else {
|
|
if (a()) {
|
|
return;
|
|
}
|
|
this.a.onNext(t);
|
|
}
|
|
}
|
|
|
|
@Override // java.util.concurrent.atomic.AtomicReference
|
|
public String toString() {
|
|
return String.format("%s{%s}", CreateEmitter.class.getSimpleName(), super.toString());
|
|
}
|
|
|
|
public boolean a() {
|
|
return DisposableHelper.isDisposed(get());
|
|
}
|
|
}
|
|
}
|