He-Pin commented on code in PR #1659:
URL: https://github.com/apache/pekko/pull/1659#discussion_r1900318510


##########
stream/src/main/scala/org/apache/pekko/stream/impl/fusing/Ops.scala:
##########
@@ -1411,37 +1411,40 @@ private[stream] object Collect {
       override def preStart(): Unit = buffer = BufferImpl(parallelism, 
inheritedAttributes)
 
       def futureCompleted(result: Try[Out]): Unit = {
-        def isCompleted = isClosed(in) && todo == 0
         inFlight -= 1
         result match {
-          case Success(elem) if elem != null =>
-            if (isAvailable(out)) {
-              if (!hasBeenPulled(in)) tryPull(in)
-              push(out, elem)
-              if (isCompleted) completeStage()
-            } else buffer.enqueue(elem)
-          case Success(_) =>
-            if (isCompleted) completeStage()
-            else if (!hasBeenPulled(in)) tryPull(in)
+          case Success(elem) =>
+            if (elem != null) {
+              if (isAvailable(out)) {
+                push(out, elem)
+              } else buffer.enqueue(elem)
+            }
+
           case Failure(ex) =>
             if (decider(ex) == Supervision.Stop) failStage(ex)
-            else if (isCompleted) completeStage()
-            else if (!hasBeenPulled(in)) tryPull(in)
         }
+        pullIfNeeded()
+      }
+
+      private def pullIfNeeded(): Unit = {
+        val leftTodo = todo
+        if (isClosed(in) && leftTodo == 0) completeStage()
+        else if (leftTodo < parallelism && !hasBeenPulled(in)) tryPull(in)
       }
 
       override def onPush(): Unit = {
         try {
           val future = f(grab(in))
           inFlight += 1
           future.value match {
-            case None    => 
future.onComplete(invokeFutureCB)(pekko.dispatch.ExecutionContexts.parasitic)
+            case None =>
+              
future.onComplete(invokeFutureCB)(pekko.dispatch.ExecutionContexts.parasitic)
+              pullIfNeeded()
             case Some(v) => futureCompleted(v)
           }
         } catch {
           case NonFatal(ex) => if (decider(ex) == Supervision.Stop) 
failStage(ex)
         }
-        if (todo < parallelism && !hasBeenPulled(in)) tryPull(in)

Review Comment:
   will try pull in `futureCompleted(v)` 



-- 
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: notifications-unsubscr...@pekko.apache.org

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


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

Reply via email to