Skip to content

Commit

Permalink
Fix variable name and add clarifying comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Dec 3, 2024
1 parent 7b60c05 commit 39bf6b1
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,14 @@ public void accept(Void ignore, Throwable exception) {
// Create stage for next group
List<SuspendableActivity> activities = List.copyOf(groups.next());
CompletableFuture<Void> groupStage = new CompletableFuture<>();
// Reuse groupCompleter instance as completion handler
groupStage.whenComplete(this);
if (activities.isEmpty()) {
// No activities, complete immediately
groupStage.complete(null);
} else {
// Counter used to determine when to complete group stage
AtomicInteger groupCounter = new AtomicInteger(activities.size());
// Counter used to determine when all activities have complete
AtomicInteger activityCounter = new AtomicInteger(activities.size());
for (SuspendableActivity activity : activities) {
BiConsumer<Void, Throwable> activityCompleter = new BiConsumer<>() {
@Override
Expand All @@ -177,7 +178,7 @@ public void accept(Void ignore, Throwable exception) {
} finally {
groupStage.completeExceptionally(exception);
}
} else if (groupCounter.decrementAndGet() == 0) {
} else if (activityCounter.decrementAndGet() == 0) {
// All activities of group have completed
groupStage.complete(null);
}
Expand Down

0 comments on commit 39bf6b1

Please sign in to comment.