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


##########
api/src/main/java/org/apache/iceberg/io/CloseableIterable.java:
##########
@@ -75,6 +75,31 @@ 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 der 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 {
+        iterable.close();
+        onCompletionRunnable.run();

Review Comment:
   good catch, that makes definitely sense. Updated and added a test



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to