fix: cancellation exception.

This commit is contained in:
huanghongxun 2021-10-01 23:49:13 +08:00
parent de9233fba5
commit cc8dd77d90
2 changed files with 4 additions and 6 deletions

View File

@ -98,7 +98,7 @@ public class LibraryDownloadTask extends Task<Void> {
Exception t = task.getException();
if (t instanceof DownloadException)
throw new LibraryDownloadException(library, t.getCause());
else if (t == null)
else if (t instanceof CancellationException)
throw new CancellationException();
else
throw new LibraryDownloadException(library, t);

View File

@ -105,8 +105,10 @@ public final class AsyncTaskExecutor extends TaskExecutor {
.thenComposeAsync(unused -> {
totTask.addAndGet(tasks.size());
if (isCancelled())
if (isCancelled()) {
for (Task<?> task : tasks) task.setException(new CancellationException());
return CompletableFuture.runAsync(this::checkCancellation);
}
return CompletableFuture.allOf(tasks.stream()
.map(task -> CompletableFuture.completedFuture(null)
@ -130,8 +132,6 @@ public final class AsyncTaskExecutor extends TaskExecutor {
}
private <T> CompletableFuture<T> executeCompletableFutureTask(Task<?> parentTask, CompletableFutureTask<T> task) {
checkCancellation();
return CompletableFuture.completedFuture(null)
.thenComposeAsync(unused -> {
checkCancellation();
@ -202,8 +202,6 @@ public final class AsyncTaskExecutor extends TaskExecutor {
}
private <T> CompletableFuture<T> executeNormalTask(Task<?> parentTask, Task<T> task) {
checkCancellation();
return CompletableFuture.completedFuture(null)
.thenComposeAsync(unused -> {
checkCancellation();