You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/08/05 10:17:56 UTC

[GitHub] [iceberg] nastra commented on a diff in pull request #5407: Core: Add RESTScanReporter to send scan report to REST endpoint

nastra commented on code in PR #5407:
URL: https://github.com/apache/iceberg/pull/5407#discussion_r938673069


##########
api/src/main/java/org/apache/iceberg/io/CloseableIterable.java:
##########
@@ -73,6 +74,36 @@ public CloseableIterator<E> iterator() {
     };
   }
 
+  /**
+   * Will run the given runnable when {@link CloseableIterable#close()} has been called.
+   *
+   * @param iterable The underlying {@link CloseableIterable} to iterate over
+   * @param onCompletionRunnable The runnable to run after the underlying iterable was closed
+   * @param <E> The type of the underlying iterable
+   * @return A new {@link CloseableIterable} where the runnable will be executed as the final step
+   *     after {@link CloseableIterable#close()} has been called
+   */
+  static <E> CloseableIterable<E> whenComplete(
+      CloseableIterable<E> iterable, Runnable onCompletionRunnable) {
+    Preconditions.checkNotNull(
+        onCompletionRunnable, "Cannot execute a null Runnable after completion");
+    return new CloseableIterable<E>() {
+      @Override
+      public void close() throws IOException {
+        try {
+          iterable.close();
+        } finally {
+          onCompletionRunnable.run();
+        }
+      }
+
+      @Override
+      public CloseableIterator<E> iterator() {
+        return CloseableIterator.withClose(iterable.iterator());

Review Comment:
   you're right, this was an oversight. no need to wrap this. Fixed in https://github.com/apache/iceberg/pull/5446



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org