what-the-bank/sources/o/FutureC13185fTT.java

145 lines
4.2 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package o;
import java.util.NoSuchElementException;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
/* renamed from: o.fTT, reason: case insensitive filesystem */
/* loaded from: classes6.dex */
public final class FutureC13185fTT<T> extends CountDownLatch implements InterfaceC13174fSv<T>, Future<T>, fSJ {
private AtomicReference<fSJ> a;
private Throwable b;
private T c;
@Override // o.fSJ
public final void dispose() {
}
public FutureC13185fTT() {
super(1);
this.a = new AtomicReference<>();
}
@Override // java.util.concurrent.Future
public final boolean cancel(boolean z) {
while (true) {
fSJ fsj = this.a.get();
if (fsj == this || fsj == EnumC13192fTf.DISPOSED) {
return false;
}
AtomicReference<fSJ> atomicReference = this.a;
EnumC13192fTf enumC13192fTf = EnumC13192fTf.DISPOSED;
while (!atomicReference.compareAndSet(fsj, enumC13192fTf)) {
if (atomicReference.get() != fsj) {
break;
}
}
if (fsj != null) {
fsj.dispose();
}
countDown();
return true;
}
}
@Override // java.util.concurrent.Future
public final boolean isCancelled() {
return EnumC13192fTf.c(this.a.get());
}
@Override // java.util.concurrent.Future
public final boolean isDone() {
return getCount() == 0;
}
@Override // java.util.concurrent.Future
public final T get() throws InterruptedException, ExecutionException {
if (getCount() != 0) {
await();
}
if (isCancelled()) {
throw new CancellationException();
}
Throwable th = this.b;
if (th == null) {
return this.c;
}
throw new ExecutionException(th);
}
@Override // java.util.concurrent.Future
public final T get(long j, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
if (getCount() != 0 && !await(j, timeUnit)) {
throw new TimeoutException(fYR.a(j, timeUnit));
}
if (isCancelled()) {
throw new CancellationException();
}
Throwable th = this.b;
if (th == null) {
return this.c;
}
throw new ExecutionException(th);
}
@Override // o.InterfaceC13174fSv
public final void onSubscribe(fSJ fsj) {
EnumC13192fTf.a(this.a, fsj);
}
@Override // o.InterfaceC13174fSv
public final void onNext(T t) {
if (this.c == null) {
this.c = t;
} else {
this.a.get().dispose();
onError(new IndexOutOfBoundsException("More than one element received"));
}
}
@Override // o.InterfaceC13174fSv
public final void onError(Throwable th) {
fSJ fsj;
if (this.b == null && (fsj = this.a.get()) != this && fsj != EnumC13192fTf.DISPOSED) {
AtomicReference<fSJ> atomicReference = this.a;
while (!atomicReference.compareAndSet(fsj, this)) {
if (atomicReference.get() != fsj) {
}
}
this.b = th;
countDown();
return;
}
C13418fZu.c(th);
}
@Override // o.InterfaceC13174fSv
public final void onComplete() {
if (this.c == null) {
onError(new NoSuchElementException("The source is empty"));
return;
}
fSJ fsj = this.a.get();
if (fsj == this || fsj == EnumC13192fTf.DISPOSED) {
return;
}
AtomicReference<fSJ> atomicReference = this.a;
while (!atomicReference.compareAndSet(fsj, this)) {
if (atomicReference.get() != fsj) {
return;
}
}
countDown();
}
@Override // o.fSJ
public final boolean isDisposed() {
return isDone();
}
}