package io.reactivex.internal.operators.observable; import io.reactivex.ObservableSource; 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.internal.disposables.DisposableHelper; import io.reactivex.plugins.RxJavaPlugins; /* loaded from: classes2.dex */ public final class ObservableDoOnEach extends AbstractObservableWithUpstream { final Consumer b; final Consumer c; final Action d; final Action e; static final class DoOnEachObserver implements Observer, Disposable { final Observer a; final Consumer b; final Consumer c; final Action d; final Action e; Disposable f; boolean g; DoOnEachObserver(Observer observer, Consumer consumer, Consumer consumer2, Action action, Action action2) { this.a = observer; this.b = consumer; this.c = consumer2; this.d = action; this.e = action2; } @Override // io.reactivex.disposables.Disposable public void dispose() { this.f.dispose(); } @Override // io.reactivex.Observer public void onComplete() { if (this.g) { return; } try { this.d.run(); this.g = true; this.a.onComplete(); try { this.e.run(); } catch (Throwable th) { Exceptions.b(th); RxJavaPlugins.b(th); } } catch (Throwable th2) { Exceptions.b(th2); onError(th2); } } @Override // io.reactivex.Observer public void onError(Throwable th) { if (this.g) { RxJavaPlugins.b(th); return; } this.g = true; try { this.c.accept(th); } catch (Throwable th2) { Exceptions.b(th2); th = new CompositeException(th, th2); } this.a.onError(th); try { this.e.run(); } catch (Throwable th3) { Exceptions.b(th3); RxJavaPlugins.b(th3); } } @Override // io.reactivex.Observer public void onNext(T t) { if (this.g) { return; } try { this.b.accept(t); this.a.onNext(t); } catch (Throwable th) { Exceptions.b(th); this.f.dispose(); onError(th); } } @Override // io.reactivex.Observer public void onSubscribe(Disposable disposable) { if (DisposableHelper.validate(this.f, disposable)) { this.f = disposable; this.a.onSubscribe(this); } } } public ObservableDoOnEach(ObservableSource observableSource, Consumer consumer, Consumer consumer2, Action action, Action action2) { super(observableSource); this.b = consumer; this.c = consumer2; this.d = action; this.e = action2; } @Override // io.reactivex.Observable public void subscribeActual(Observer observer) { this.a.subscribe(new DoOnEachObserver(observer, this.b, this.c, this.d, this.e)); } }