REQ-2481: 简单重构

This commit is contained in:
yanglin 2024-06-03 17:54:02 +08:00
parent 7100dc09db
commit ca37177e12

View File

@ -14,19 +14,19 @@ import java.util.concurrent.TimeoutException;
class AsyncTasks<T> {
private final List<CompletableFuture<T>> futures = Collections.synchronizedList(new ArrayList<>());
private final boolean removeWhenComplete;
private final boolean removeFutureWhenComplete;
AsyncTasks() {
this(true);
}
AsyncTasks(boolean removeWhenComplete) {
this.removeWhenComplete = removeWhenComplete;
AsyncTasks(boolean removeFutureWhenComplete) {
this.removeFutureWhenComplete = removeFutureWhenComplete;
}
void add(CompletableFuture<T> future) {
futures.add(future);
if (removeWhenComplete)
if (removeFutureWhenComplete)
future.whenComplete((unused, throwable) -> futures.remove(future));
}