discord-jadx/app/src/main/java/z/g.java

161 lines
4.0 KiB
Java

package z;
import bolts.ExecutorException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
/* compiled from: Task */
public class g<TResult> {
public static final Executor a;
public static g<?> b = new g<>((Object) null);
/* renamed from: c reason: collision with root package name */
public static g<Boolean> f2974c = new g<>(Boolean.TRUE);
public static g<Boolean> d = new g<>(Boolean.FALSE);
public final Object e = new Object();
public boolean f;
public boolean g;
public TResult h;
public Exception i;
public boolean j;
public List<c<TResult, Void>> k = new ArrayList();
static {
b bVar = b.a;
ExecutorService executorService = bVar.b;
a = bVar.f2972c;
Executor executor = a.a.e;
new g(true);
}
public g() {
}
public g(TResult tresult) {
h(tresult);
}
public g(boolean z2) {
if (z2) {
g();
} else {
h(null);
}
}
public static <TResult> g<TResult> a(Callable<TResult> callable, Executor executor) {
h hVar = new h();
try {
executor.execute(new f(hVar, callable));
} catch (Exception e) {
hVar.b(new ExecutorException(e));
}
return hVar.a;
}
public static <TResult> g<TResult> c(Exception exc) {
boolean z2;
g<TResult> gVar = new g<>();
synchronized (gVar.e) {
z2 = false;
if (!gVar.f) {
gVar.f = true;
gVar.i = exc;
gVar.j = false;
gVar.e.notifyAll();
gVar.f();
z2 = true;
}
}
if (z2) {
return gVar;
}
throw new IllegalStateException("Cannot set the error on a completed task.");
}
/* JADX DEBUG: Type inference failed for r7v3. Raw type applied. Possible types: z.g<TResult>, z.g<TContinuationResult> */
public <TContinuationResult> g<TContinuationResult> b(c<TResult, TContinuationResult> cVar) {
boolean z2;
Executor executor = a;
h hVar = new h();
synchronized (this.e) {
synchronized (this.e) {
z2 = this.f;
}
if (!z2) {
this.k.add(new d(this, hVar, cVar, executor));
}
}
if (z2) {
try {
executor.execute(new e(hVar, cVar, this));
} catch (Exception e) {
hVar.b(new ExecutorException(e));
}
}
return (g<TResult>) hVar.a;
}
public Exception d() {
Exception exc;
synchronized (this.e) {
exc = this.i;
if (exc != null) {
this.j = true;
}
}
return exc;
}
public boolean e() {
boolean z2;
synchronized (this.e) {
z2 = d() != null;
}
return z2;
}
public final void f() {
synchronized (this.e) {
for (c<TResult, Void> cVar : this.k) {
try {
cVar.a(this);
} catch (RuntimeException e) {
throw e;
} catch (Exception e2) {
throw new RuntimeException(e2);
}
}
this.k = null;
}
}
public boolean g() {
synchronized (this.e) {
if (this.f) {
return false;
}
this.f = true;
this.g = true;
this.e.notifyAll();
f();
return true;
}
}
public boolean h(TResult tresult) {
synchronized (this.e) {
if (this.f) {
return false;
}
this.f = true;
this.h = tresult;
this.e.notifyAll();
f();
return true;
}
}
}