rdblue commented on code in PR #10691:
URL: https://github.com/apache/iceberg/pull/10691#discussion_r1677179876


##########
core/src/main/java/org/apache/iceberg/util/ParallelIterable.java:
##########
@@ -136,19 +152,20 @@ private boolean checkTasks() {
         }
       }
 
-      return !closed && (tasks.hasNext() || hasRunningTask);
+      return !closed.get() && (tasks.hasNext() || hasRunningTask);
     }
 
-    private Future<?> submitNextTask() {
-      if (!closed && tasks.hasNext()) {
-        return workerPool.submit(tasks.next());
+    private Future<Optional<Task<T>>> submitNextTask() {
+      if (!closed.get() && (!yieldedTasks.isEmpty() || tasks.hasNext())) {
+        return workerPool.submit(
+            !yieldedTasks.isEmpty() ? yieldedTasks.removeFirst() : 
tasks.next());

Review Comment:
   If both `yieldedTasks.removeFirst()` and `tasks.next()` are actually called 
and executed then some results will be discarded. That means correctness here 
depends on whether the ternary operator will actually execute the expression 
that is not used.
   
   While this _is_ correct and the unused expression is not executed, I 
generally prefer not to rely on behavior like that since it is hard to 
remember. I think it is better to use a standard `if`/`else` statement:
   
   ```java
     if (yieldedTasks.isEmpty()) {
       return workerPool.submit(tasks.next());
     } else {
       return workerPool.submit(yieldedTasks.removeFirst());
     }
   ```



-- 
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-unsubscr...@iceberg.apache.org

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


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

Reply via email to