package o; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; /* loaded from: classes6.dex */ public final class fWT extends fUX { private fSS, ? extends InterfaceC13169fSq> a; public fWT(InterfaceC13169fSq interfaceC13169fSq, fSS, ? extends InterfaceC13169fSq> fss) { super(interfaceC13169fSq); this.a = fss; } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv interfaceC13174fSv) { C13420fZw c13420fZw = new C13420fZw(C13389fZA.d()); try { InterfaceC13169fSq interfaceC13169fSq = (InterfaceC13169fSq) Objects.requireNonNull(this.a.a(c13420fZw), "The handler returned a null ObservableSource"); LWm lWm = new LWm(interfaceC13174fSv, c13420fZw, this.c); interfaceC13174fSv.onSubscribe(lWm); interfaceC13169fSq.subscribe(lWm.c); lWm.c(); } catch (Throwable th) { C13147fSI.c(th); EnumC13195fTi.a(th, interfaceC13174fSv); } } /* loaded from: classes6.dex */ static final class LWm extends AtomicInteger implements InterfaceC13174fSv, fSJ { final InterfaceC13174fSv a; private volatile boolean b; private AbstractC13422fZy h; private InterfaceC13169fSq j; private AtomicInteger i = new AtomicInteger(); final C13355fYI e = new C13355fYI(); final LWm.Sts c = new Sts(this); final AtomicReference d = new AtomicReference<>(); LWm(InterfaceC13174fSv interfaceC13174fSv, AbstractC13422fZy abstractC13422fZy, InterfaceC13169fSq interfaceC13169fSq) { this.a = interfaceC13174fSv; this.h = abstractC13422fZy; this.j = interfaceC13169fSq; } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { EnumC13192fTf.a(this.d, fsj); } @Override // o.InterfaceC13174fSv public final void onNext(T t) { fYQ.b(this.a, t, this, this.e); } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { EnumC13192fTf.e(this.c); InterfaceC13174fSv interfaceC13174fSv = this.a; C13355fYI c13355fYI = this.e; if (fYR.c(c13355fYI, th)) { if (getAndIncrement() == 0) { Throwable b = fYR.b(c13355fYI); if (b == null) { interfaceC13174fSv.onComplete(); return; } else { if (b != fYR.b) { interfaceC13174fSv.onError(b); return; } return; } } return; } C13418fZu.c(th); } @Override // o.InterfaceC13174fSv public final void onComplete() { EnumC13192fTf.c(this.d, null); this.b = false; this.h.onNext(0); } @Override // o.fSJ public final boolean isDisposed() { return EnumC13192fTf.c(this.d.get()); } @Override // o.fSJ public final void dispose() { EnumC13192fTf.e(this.d); EnumC13192fTf.e(this.c); } final void c() { if (this.i.getAndIncrement() != 0) { return; } while (!isDisposed()) { if (!this.b) { this.b = true; this.j.subscribe(this); } if (this.i.decrementAndGet() == 0) { return; } } } /* loaded from: classes6.dex */ final class Sts extends AtomicReference implements InterfaceC13174fSv { private LWm b; Sts(LWm lWm) { this.b = lWm; } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { EnumC13192fTf.a(this, fsj); } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { LWm lWm = this.b; EnumC13192fTf.e(lWm.d); InterfaceC13174fSv interfaceC13174fSv = lWm.a; C13355fYI c13355fYI = lWm.e; if (fYR.c(c13355fYI, th)) { if (lWm.getAndIncrement() == 0) { Throwable b = fYR.b(c13355fYI); if (b == null) { interfaceC13174fSv.onComplete(); return; } else { if (b != fYR.b) { interfaceC13174fSv.onError(b); return; } return; } } return; } C13418fZu.c(th); } @Override // o.InterfaceC13174fSv public final void onComplete() { LWm lWm = this.b; EnumC13192fTf.e(lWm.d); InterfaceC13174fSv interfaceC13174fSv = lWm.a; C13355fYI c13355fYI = lWm.e; if (lWm.getAndIncrement() == 0) { Throwable b = fYR.b(c13355fYI); if (b == null) { interfaceC13174fSv.onComplete(); } else if (b != fYR.b) { interfaceC13174fSv.onError(b); } } } @Override // o.InterfaceC13174fSv public final void onNext(Object obj) { this.b.c(); } } } }