89 lines
2.5 KiB
Java
89 lines
2.5 KiB
Java
package io.reactivex.internal.observers;
|
|
|
|
import io.reactivex.Observer;
|
|
import io.reactivex.disposables.Disposable;
|
|
import io.reactivex.exceptions.CompositeException;
|
|
import io.reactivex.exceptions.Exceptions;
|
|
import io.reactivex.functions.Action;
|
|
import io.reactivex.functions.Consumer;
|
|
import io.reactivex.functions.Predicate;
|
|
import io.reactivex.internal.disposables.DisposableHelper;
|
|
import io.reactivex.plugins.RxJavaPlugins;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class ForEachWhileObserver<T> extends AtomicReference<Disposable> implements Observer<T>, Disposable {
|
|
private static final long serialVersionUID = -4403180040475402120L;
|
|
boolean done;
|
|
final Action onComplete;
|
|
final Consumer<? super Throwable> onError;
|
|
final Predicate<? super T> onNext;
|
|
|
|
public ForEachWhileObserver(Predicate<? super T> predicate, Consumer<? super Throwable> consumer, Action action) {
|
|
this.onNext = predicate;
|
|
this.onError = consumer;
|
|
this.onComplete = action;
|
|
}
|
|
|
|
@Override // io.reactivex.disposables.Disposable
|
|
public void dispose() {
|
|
DisposableHelper.dispose(this);
|
|
}
|
|
|
|
public boolean isDisposed() {
|
|
return DisposableHelper.isDisposed(get());
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onComplete() {
|
|
if (this.done) {
|
|
return;
|
|
}
|
|
this.done = true;
|
|
try {
|
|
this.onComplete.run();
|
|
} catch (Throwable th) {
|
|
Exceptions.b(th);
|
|
RxJavaPlugins.b(th);
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onError(Throwable th) {
|
|
if (this.done) {
|
|
RxJavaPlugins.b(th);
|
|
return;
|
|
}
|
|
this.done = true;
|
|
try {
|
|
this.onError.accept(th);
|
|
} catch (Throwable th2) {
|
|
Exceptions.b(th2);
|
|
RxJavaPlugins.b(new CompositeException(th, th2));
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onNext(T t) {
|
|
if (this.done) {
|
|
return;
|
|
}
|
|
try {
|
|
if (this.onNext.a(t)) {
|
|
return;
|
|
}
|
|
dispose();
|
|
onComplete();
|
|
} catch (Throwable th) {
|
|
Exceptions.b(th);
|
|
dispose();
|
|
onError(th);
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onSubscribe(Disposable disposable) {
|
|
DisposableHelper.setOnce(this, disposable);
|
|
}
|
|
}
|