100 lines
3.1 KiB
Java
100 lines
3.1 KiB
Java
package com.google.android.gms.tasks;
|
|
|
|
import com.google.android.gms.common.internal.Preconditions;
|
|
import java.util.concurrent.CancellationException;
|
|
import java.util.concurrent.CountDownLatch;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class Tasks {
|
|
|
|
private static final class zza implements zzb {
|
|
private final CountDownLatch a;
|
|
|
|
private zza() {
|
|
this.a = new CountDownLatch(1);
|
|
}
|
|
|
|
@Override // com.google.android.gms.tasks.OnFailureListener
|
|
public final void a(Exception exc) {
|
|
this.a.countDown();
|
|
}
|
|
|
|
public final void b() throws InterruptedException {
|
|
this.a.await();
|
|
}
|
|
|
|
@Override // com.google.android.gms.tasks.OnSuccessListener
|
|
public final void onSuccess(Object obj) {
|
|
this.a.countDown();
|
|
}
|
|
|
|
@Override // com.google.android.gms.tasks.OnCanceledListener
|
|
public final void a() {
|
|
this.a.countDown();
|
|
}
|
|
|
|
/* synthetic */ zza(zzv zzvVar) {
|
|
this();
|
|
}
|
|
|
|
public final boolean a(long j, TimeUnit timeUnit) throws InterruptedException {
|
|
return this.a.await(j, timeUnit);
|
|
}
|
|
}
|
|
|
|
interface zzb extends OnCanceledListener, OnFailureListener, OnSuccessListener<Object> {
|
|
}
|
|
|
|
public static <TResult> Task<TResult> a(TResult tresult) {
|
|
zzu zzuVar = new zzu();
|
|
zzuVar.a((zzu) tresult);
|
|
return zzuVar;
|
|
}
|
|
|
|
private static <TResult> TResult b(Task<TResult> task) throws ExecutionException {
|
|
if (task.e()) {
|
|
return task.b();
|
|
}
|
|
if (task.c()) {
|
|
throw new CancellationException("Task is already canceled");
|
|
}
|
|
throw new ExecutionException(task.a());
|
|
}
|
|
|
|
public static <TResult> TResult a(Task<TResult> task) throws ExecutionException, InterruptedException {
|
|
Preconditions.a();
|
|
Preconditions.a(task, "Task must not be null");
|
|
if (task.d()) {
|
|
return (TResult) b(task);
|
|
}
|
|
zza zzaVar = new zza(null);
|
|
a(task, zzaVar);
|
|
zzaVar.b();
|
|
return (TResult) b(task);
|
|
}
|
|
|
|
public static <TResult> TResult a(Task<TResult> task, long j, TimeUnit timeUnit) throws ExecutionException, InterruptedException, TimeoutException {
|
|
Preconditions.a();
|
|
Preconditions.a(task, "Task must not be null");
|
|
Preconditions.a(timeUnit, "TimeUnit must not be null");
|
|
if (task.d()) {
|
|
return (TResult) b(task);
|
|
}
|
|
zza zzaVar = new zza(null);
|
|
a(task, zzaVar);
|
|
if (zzaVar.a(j, timeUnit)) {
|
|
return (TResult) b(task);
|
|
}
|
|
throw new TimeoutException("Timed out waiting for Task");
|
|
}
|
|
|
|
private static void a(Task<?> task, zzb zzbVar) {
|
|
task.a(TaskExecutors.a, (OnSuccessListener<? super Object>) zzbVar);
|
|
task.a(TaskExecutors.a, (OnFailureListener) zzbVar);
|
|
task.a(TaskExecutors.a, (OnCanceledListener) zzbVar);
|
|
}
|
|
}
|