Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -171,12 +172,9 @@ public static <T> T awaitEvenIfOnMainThread(Task<T> task)

task.continueWith(
TASK_CONTINUATION_EXECUTOR_SERVICE,
new Continuation<T, Object>() {
@Override
public Object then(@NonNull Task<T> task) throws Exception {
latch.countDown();
return null;
}
unusedTask -> {
latch.countDown();
return null;
});

if (Looper.getMainLooper() == Looper.myLooper()) {
Expand All @@ -185,8 +183,12 @@ public Object then(@NonNull Task<T> task) throws Exception {
latch.await();
}

if (task.isComplete()) {
if (task.isSuccessful()) {
return task.getResult();
} else if (task.isCanceled()) {
throw new CancellationException("Task is already canceled");
} else if (task.isComplete()) {
throw new IllegalStateException(task.getException());
} else {
throw new TimeoutException();
}
Expand Down