lidavidm commented on a change in pull request #9941:
URL: https://github.com/apache/arrow/pull/9941#discussion_r610631804



##########
File path: cpp/src/arrow/util/async_generator.h
##########
@@ -1149,108 +1148,197 @@ class BackgroundGenerator {
     } else {
       auto next = Future<T>::MakeFinished(std::move(state_->queue.front()));
       state_->queue.pop();
-      if (!state_->running &&
-          static_cast<int>(state_->queue.size()) <= state_->q_restart) {
-        state_->RestartTask(state_, std::move(guard));
+      if (state_->NeedsRestart()) {
+        return state_->RestartTask(state_, std::move(guard), std::move(next));
       }
       return next;
     }
-    if (!state_->running) {
-      // This branch should only be needed to start the background thread on 
the first
-      // call
-      state_->RestartTask(state_, std::move(guard));
+    // This should only trigger the very first time this method is called
+    if (state_->NeedsRestart()) {
+      return state_->RestartTask(state_, std::move(guard), 
std::move(waiting_future));
     }
     return waiting_future;
   }
 
  protected:
+  enum class BackgroundThreadState : char { Reading = 0, Quitting = 1, Idle = 
2 };

Review comment:
       This enum seems to be unused in favor of the booleans still?




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to