package o; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import o.AbstractC13173fSu; /* loaded from: classes6.dex */ public final class fVD extends fUX { private TimeUnit a; private AbstractC13173fSu b; private long d; private fSQ e; public fVD(InterfaceC13169fSq interfaceC13169fSq, long j, TimeUnit timeUnit, AbstractC13173fSu abstractC13173fSu, fSQ fsq) { super(interfaceC13169fSq); this.d = j; this.a = timeUnit; this.b = abstractC13173fSu; this.e = fsq; } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv interfaceC13174fSv) { this.c.subscribe(new IeS(new C13406fZi(interfaceC13174fSv), this.d, this.a, this.b.c(), this.e)); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static final class IeS implements InterfaceC13174fSv, fSJ { private boolean a; private fSQ b; final InterfaceC13174fSv c; private long d; volatile long e; private fSJ g; private AbstractC13173fSu.Sts h; private TimeUnit i; private HBt j; IeS(InterfaceC13174fSv interfaceC13174fSv, long j, TimeUnit timeUnit, AbstractC13173fSu.Sts sts, fSQ fsq) { this.c = interfaceC13174fSv; this.d = j; this.i = timeUnit; this.h = sts; this.b = fsq; } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { if (EnumC13192fTf.d(this.g, fsj)) { this.g = fsj; this.c.onSubscribe(this); } } @Override // o.InterfaceC13174fSv public final void onNext(T t) { if (this.a) { return; } long j = this.e + 1; this.e = j; HBt hBt = this.j; if (hBt != null) { hBt.dispose(); } fSQ fsq = this.b; if (fsq != null && hBt != null) { try { fsq.c(this.j.b); } catch (Throwable th) { C13147fSI.c(th); this.g.dispose(); this.c.onError(th); this.a = true; } } HBt hBt2 = new HBt<>(t, j, this); this.j = hBt2; EnumC13192fTf.c(hBt2, this.h.a(hBt2, this.d, this.i)); } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { if (this.a) { C13418fZu.c(th); return; } HBt hBt = this.j; if (hBt != null) { hBt.dispose(); } this.a = true; this.c.onError(th); this.h.dispose(); } @Override // o.InterfaceC13174fSv public final void onComplete() { if (this.a) { return; } this.a = true; HBt hBt = this.j; if (hBt != null) { hBt.dispose(); } if (hBt != null) { hBt.run(); } this.c.onComplete(); this.h.dispose(); } @Override // o.fSJ public final void dispose() { this.g.dispose(); this.h.dispose(); } @Override // o.fSJ public final boolean isDisposed() { return this.h.isDisposed(); } } /* loaded from: classes6.dex */ static final class HBt extends AtomicReference implements Runnable, fSJ { private IeS a; final T b; private long c; private AtomicBoolean d = new AtomicBoolean(); HBt(T t, long j, IeS ieS) { this.b = t; this.c = j; this.a = ieS; } @Override // java.lang.Runnable public final void run() { if (this.d.compareAndSet(false, true)) { IeS ieS = this.a; long j = this.c; T t = this.b; if (j == ieS.e) { ieS.c.onNext(t); dispose(); } } } @Override // o.fSJ public final void dispose() { EnumC13192fTf.e(this); } @Override // o.fSJ public final boolean isDisposed() { return get() == EnumC13192fTf.DISPOSED; } } }