package o; import java.util.NoSuchElementException; /* loaded from: classes6.dex */ public final class fVL extends fUX { private T a; private long b; private boolean d; public fVL(InterfaceC13169fSq interfaceC13169fSq, long j, T t, boolean z) { super(interfaceC13169fSq); this.b = j; this.a = t; this.d = z; } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv interfaceC13174fSv) { this.c.subscribe(new LWm(interfaceC13174fSv, this.b, this.a, this.d)); } /* loaded from: classes6.dex */ static final class LWm implements InterfaceC13174fSv, fSJ { private boolean a; private long b; private boolean c; private T d; private InterfaceC13174fSv e; private fSJ f; private long h; LWm(InterfaceC13174fSv interfaceC13174fSv, long j, T t, boolean z) { this.e = interfaceC13174fSv; this.h = j; this.d = t; this.c = z; } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { if (EnumC13192fTf.d(this.f, fsj)) { this.f = fsj; this.e.onSubscribe(this); } } @Override // o.fSJ public final void dispose() { this.f.dispose(); } @Override // o.fSJ public final boolean isDisposed() { return this.f.isDisposed(); } @Override // o.InterfaceC13174fSv public final void onNext(T t) { if (this.a) { return; } long j = this.b; if (j != this.h) { this.b = j + 1; return; } this.a = true; this.f.dispose(); this.e.onNext(t); this.e.onComplete(); } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { if (this.a) { C13418fZu.c(th); } else { this.a = true; this.e.onError(th); } } @Override // o.InterfaceC13174fSv public final void onComplete() { if (this.a) { return; } this.a = true; T t = this.d; if (t == null && this.c) { this.e.onError(new NoSuchElementException()); return; } if (t != null) { this.e.onNext(t); } this.e.onComplete(); } } }