jimu-decompiled/sources/io/reactivex/observers/SerializedObserver.java
2025-05-13 19:24:51 +02:00

144 lines
4.6 KiB
Java

package io.reactivex.observers;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.internal.disposables.DisposableHelper;
import io.reactivex.internal.util.AppendOnlyLinkedArrayList;
import io.reactivex.internal.util.NotificationLite;
import io.reactivex.plugins.RxJavaPlugins;
/* loaded from: classes2.dex */
public final class SerializedObserver<T> implements Observer<T>, Disposable {
final Observer<? super T> a;
final boolean b;
Disposable c;
boolean d;
AppendOnlyLinkedArrayList<Object> e;
volatile boolean f;
public SerializedObserver(Observer<? super T> observer) {
this(observer, false);
}
void a() {
AppendOnlyLinkedArrayList<Object> appendOnlyLinkedArrayList;
do {
synchronized (this) {
appendOnlyLinkedArrayList = this.e;
if (appendOnlyLinkedArrayList == null) {
this.d = false;
return;
}
this.e = null;
}
} while (!appendOnlyLinkedArrayList.a((Observer) this.a));
}
@Override // io.reactivex.disposables.Disposable
public void dispose() {
this.c.dispose();
}
@Override // io.reactivex.Observer
public void onComplete() {
if (this.f) {
return;
}
synchronized (this) {
if (this.f) {
return;
}
if (!this.d) {
this.f = true;
this.d = true;
this.a.onComplete();
} else {
AppendOnlyLinkedArrayList<Object> appendOnlyLinkedArrayList = this.e;
if (appendOnlyLinkedArrayList == null) {
appendOnlyLinkedArrayList = new AppendOnlyLinkedArrayList<>(4);
this.e = appendOnlyLinkedArrayList;
}
appendOnlyLinkedArrayList.a((AppendOnlyLinkedArrayList<Object>) NotificationLite.complete());
}
}
}
@Override // io.reactivex.Observer
public void onError(Throwable th) {
if (this.f) {
RxJavaPlugins.b(th);
return;
}
synchronized (this) {
boolean z = true;
if (!this.f) {
if (this.d) {
this.f = true;
AppendOnlyLinkedArrayList<Object> appendOnlyLinkedArrayList = this.e;
if (appendOnlyLinkedArrayList == null) {
appendOnlyLinkedArrayList = new AppendOnlyLinkedArrayList<>(4);
this.e = appendOnlyLinkedArrayList;
}
Object error = NotificationLite.error(th);
if (this.b) {
appendOnlyLinkedArrayList.a((AppendOnlyLinkedArrayList<Object>) error);
} else {
appendOnlyLinkedArrayList.b(error);
}
return;
}
this.f = true;
this.d = true;
z = false;
}
if (z) {
RxJavaPlugins.b(th);
} else {
this.a.onError(th);
}
}
}
@Override // io.reactivex.Observer
public void onNext(T t) {
if (this.f) {
return;
}
if (t == null) {
this.c.dispose();
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
return;
}
synchronized (this) {
if (this.f) {
return;
}
if (!this.d) {
this.d = true;
this.a.onNext(t);
a();
} else {
AppendOnlyLinkedArrayList<Object> appendOnlyLinkedArrayList = this.e;
if (appendOnlyLinkedArrayList == null) {
appendOnlyLinkedArrayList = new AppendOnlyLinkedArrayList<>(4);
this.e = appendOnlyLinkedArrayList;
}
appendOnlyLinkedArrayList.a((AppendOnlyLinkedArrayList<Object>) NotificationLite.next(t));
}
}
}
@Override // io.reactivex.Observer
public void onSubscribe(Disposable disposable) {
if (DisposableHelper.validate(this.c, disposable)) {
this.c = disposable;
this.a.onSubscribe(this);
}
}
public SerializedObserver(Observer<? super T> observer, boolean z) {
this.a = observer;
this.b = z;
}
}