REQ-2481: 简单重构
This commit is contained in:
parent
7100dc09db
commit
ca37177e12
@ -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));
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user