lhotari commented on code in PR #24698:
URL: https://github.com/apache/pulsar/pull/24698#discussion_r2319576255
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PatternMultiTopicsConsumerImpl.java:
##########
@@ -385,16 +385,14 @@ public CompletableFuture<Void> closeAsync() {
timeout.cancel();
recheckPatternTimeout = null;
}
- List<CompletableFuture<?>> closeFutures = new ArrayList<>(2);
- if (watcherFuture.isDone() &&
!watcherFuture.isCompletedExceptionally()) {
- TopicListWatcher watcher = watcherFuture.getNow(null);
- // watcher can be null when subscription mode is not persistent
- if (watcher != null) {
- closeFutures.add(watcher.closeAsync());
- }
- }
-
closeFutures.add(updateTaskQueue.cancelAllAndWaitForTheRunningTask().thenCompose(__
-> super.closeAsync()));
- return FutureUtil.waitForAll(closeFutures);
+ CompletableFuture<Void> topicListWatcherCloseFuture =
+ watcherFuture.isCompletedExceptionally() ?
CompletableFuture.completedFuture(null)
+ : watcherFuture.thenCompose(
+ topicListWatcher -> topicListWatcher != null ?
topicListWatcher.closeAsync()
+ : CompletableFuture.completedFuture(null));
Review Comment:
There's a simpler way to achieve a similar result and to ignore any
exceptions:
```suggestion
CompletableFuture<Void> watcherCloseFuture = watcherFuture
.thenCompose(TopicListWatcher::closeAsync)
.exceptionally(t -> null);
```
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PatternMultiTopicsConsumerImpl.java:
##########
@@ -385,16 +385,14 @@ public CompletableFuture<Void> closeAsync() {
timeout.cancel();
recheckPatternTimeout = null;
}
- List<CompletableFuture<?>> closeFutures = new ArrayList<>(2);
- if (watcherFuture.isDone() &&
!watcherFuture.isCompletedExceptionally()) {
- TopicListWatcher watcher = watcherFuture.getNow(null);
- // watcher can be null when subscription mode is not persistent
- if (watcher != null) {
- closeFutures.add(watcher.closeAsync());
- }
- }
-
closeFutures.add(updateTaskQueue.cancelAllAndWaitForTheRunningTask().thenCompose(__
-> super.closeAsync()));
- return FutureUtil.waitForAll(closeFutures);
+ CompletableFuture<Void> topicListWatcherCloseFuture =
+ watcherFuture.isCompletedExceptionally() ?
CompletableFuture.completedFuture(null)
+ : watcherFuture.thenCompose(
+ topicListWatcher -> topicListWatcher != null ?
topicListWatcher.closeAsync()
+ : CompletableFuture.completedFuture(null));
+ CompletableFuture<Void> runningTaskCancelCloseFuture =
+
updateTaskQueue.cancelAllAndWaitForTheRunningTask().thenCompose(__ ->
super.closeAsync());
+ return
FutureUtil.waitForAll(Lists.newArrayList(topicListWatcherCloseFuture,
runningTaskCancelCloseFuture));
Review Comment:
I'd assume that `super.closeAsync()` should be called after
`topicListWatcherCloseFuture` and
`updateTaskQueue.cancelAllAndWaitForTheRunningTask()` have completed, ignoring
any errors.
Something like this:
```suggestion
CompletableFuture<Void> runningTaskCancelFuture =
updateTaskQueue.cancelAllAndWaitForTheRunningTask();
return
FutureUtil.waitForAll(Lists.newArrayList(topicListWatcherCloseFuture,
runningTaskCancelFuture)).exceptionally(t -> null).thenCompose(__ ->
super.closeAsync());
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]