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



##########
File path: cpp/src/arrow/util/async_generator.h
##########
@@ -280,6 +280,150 @@ AsyncGenerator<V> MakeMappedGenerator(AsyncGenerator<T> 
source_generator,
   return MappingGenerator<T, V>(std::move(source_generator), std::move(map));
 }
 
+/// \see MakeSequencingGenerator
+template <typename T, typename Comp, typename IsNext>
+class SequencingGenerator {
+ public:
+  SequencingGenerator(AsyncGenerator<T> source, Comp compare, IsNext is_next,
+                      T initial_value)
+      : state_(std::make_shared<State>(std::move(source), std::move(compare),
+                                       std::move(is_next), 
std::move(initial_value))) {}
+
+  Future<T> operator()() {
+    util::optional<Result<T>> result;
+    {
+      auto guard = state_->mutex.Lock();
+      if (!state_->queue.empty()) {
+        if (!state_->queue.top().ok() ||
+            state_->is_next(state_->previous_value, *state_->queue.top())) {
+          result = std::move(state_->queue.top());
+          if (result->ok()) {
+            state_->previous_value = **result;
+          }
+          state_->queue.pop();
+        }

Review comment:
       Good observation.  I reworked the logic based on this and I think it is 
much clearer now (and I got rid of the optional)




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