package o; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; /* loaded from: classes6.dex */ public final class fWX extends fUX { private fSQ a; private boolean b; private long d; private AbstractC13173fSu e; private TimeUnit i; public fWX(InterfaceC13169fSq interfaceC13169fSq, long j, TimeUnit timeUnit, AbstractC13173fSu abstractC13173fSu, boolean z, fSQ fsq) { super(interfaceC13169fSq); this.d = j; this.i = timeUnit; this.e = abstractC13173fSu; this.b = z; this.a = fsq; } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv interfaceC13174fSv) { C13406fZi c13406fZi = new C13406fZi(interfaceC13174fSv); if (this.b) { this.c.subscribe(new RVV(c13406fZi, this.d, this.i, this.e, this.a)); } else { this.c.subscribe(new IeS(c13406fZi, this.d, this.i, this.e, this.a)); } } /* loaded from: classes6.dex */ static abstract class LWm extends AtomicReference implements InterfaceC13174fSv, fSJ, Runnable { private long a; private fSQ b; private AtomicReference c = new AtomicReference<>(); private AbstractC13173fSu d; final InterfaceC13174fSv e; private fSJ g; private TimeUnit i; abstract void e(); LWm(InterfaceC13174fSv interfaceC13174fSv, long j, TimeUnit timeUnit, AbstractC13173fSu abstractC13173fSu, fSQ fsq) { this.e = interfaceC13174fSv; this.a = j; this.i = timeUnit; this.d = abstractC13173fSu; this.b = fsq; } @Override // o.InterfaceC13174fSv public void onSubscribe(fSJ fsj) { if (EnumC13192fTf.d(this.g, fsj)) { this.g = fsj; this.e.onSubscribe(this); AbstractC13173fSu abstractC13173fSu = this.d; long j = this.a; EnumC13192fTf.c(this.c, abstractC13173fSu.d(this, j, j, this.i)); } } @Override // o.InterfaceC13174fSv public void onNext(T t) { fSQ fsq; T andSet = getAndSet(t); if (andSet == null || (fsq = this.b) == null) { return; } try { fsq.c(andSet); } catch (Throwable th) { C13147fSI.c(th); EnumC13192fTf.e(this.c); this.g.dispose(); this.e.onError(th); } } @Override // o.InterfaceC13174fSv public void onError(Throwable th) { EnumC13192fTf.e(this.c); this.e.onError(th); } @Override // o.InterfaceC13174fSv public void onComplete() { EnumC13192fTf.e(this.c); e(); } @Override // o.fSJ public void dispose() { EnumC13192fTf.e(this.c); this.g.dispose(); } @Override // o.fSJ public boolean isDisposed() { return this.g.isDisposed(); } } /* loaded from: classes6.dex */ static final class IeS extends LWm { IeS(InterfaceC13174fSv interfaceC13174fSv, long j, TimeUnit timeUnit, AbstractC13173fSu abstractC13173fSu, fSQ fsq) { super(interfaceC13174fSv, j, timeUnit, abstractC13173fSu, fsq); } @Override // o.fWX.LWm final void e() { this.e.onComplete(); } @Override // java.lang.Runnable public final void run() { T andSet = getAndSet(null); if (andSet != null) { this.e.onNext(andSet); } } } /* loaded from: classes6.dex */ static final class RVV extends LWm { private AtomicInteger c; RVV(InterfaceC13174fSv interfaceC13174fSv, long j, TimeUnit timeUnit, AbstractC13173fSu abstractC13173fSu, fSQ fsq) { super(interfaceC13174fSv, j, timeUnit, abstractC13173fSu, fsq); this.c = new AtomicInteger(1); } @Override // java.lang.Runnable public final void run() { if (this.c.incrementAndGet() == 2) { T andSet = getAndSet(null); if (andSet != null) { this.e.onNext(andSet); } if (this.c.decrementAndGet() == 0) { this.e.onComplete(); } } } @Override // o.fWX.LWm final void e() { T andSet = getAndSet(null); if (andSet != null) { this.e.onNext(andSet); } if (this.c.decrementAndGet() == 0) { this.e.onComplete(); } } } }