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



##########
File path: cpp/src/arrow/util/async_generator.h
##########
@@ -1247,10 +1286,23 @@ class BackgroundGenerator {
           waiting_future.MarkFinished(next);
         }
       }
+      {
+        auto guard = state->mutex.Lock();
+        state->running_at_all = false;
+        if (state->finished) {
+          state->task_finished.MarkFinished();
+        }
+      }
     }
   };
 
   std::shared_ptr<State> state_;
+  // state_ is held by both the generator and the background thread so it 
won't be cleaned
+  // up when all consumer references are relinquished.  cleanup_ is only held 
by the
+  // generator so it will be destructed when the last consumer reference is 
gone.  We use
+  // this to cleanup / stop the background generator in case the consuming end 
stops
+  // listening (e.g. due to a downstream error)
+  std::shared_ptr<Cleanup> cleanup_;

Review comment:
       Yes, I was torn on this myself.  If `weak_ptr` seems like a cleaner 
approach I can do that.




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