He-Pin commented on code in PR #628:
URL: https://github.com/apache/incubator-pekko/pull/628#discussion_r1316115225


##########
stream/src/main/scala/org/apache/pekko/stream/scaladsl/Flow.scala:
##########
@@ -1141,7 +1140,18 @@ trait FlowOps[+Out, +Mat] {
    *
    * @see [[#mapAsync]]
    */
-  def mapAsyncUnordered[T](parallelism: Int)(f: Out => Future[T]): Repr[T] = 
via(MapAsyncUnordered(parallelism, f))
+  def mapAsyncUnordered[T](parallelism: Int)(f: Out => Future[T]): Repr[T] =
+    unsafeTransformUnordered[T](parallelism) { (out, emitter) =>
+      val future = f(out)
+      future.value match {
+        case Some(elem) => 
emitter.asInstanceOf[UnsafeEmitter[T]].handleNow(elem)
+        case None       => 
future.onComplete(emitter.handle)(pekko.dispatch.ExecutionContexts.parasitic)
+      }
+    }

Review Comment:
   I tried with another idea, better in Scala, but will make the function type 
in Java much complex.
   ```scala
       unsafeTransformUnordered[T](parallelism) { implicit emitter => out =>
         import EmitterOps._
         import EmitterUnsafeOps._
         val future = f(out)
         future.value match {
           case Some(elem) => handleNow(elem)
           case None       => 
future.onComplete(handle)(pekko.dispatch.ExecutionContexts.parasitic)
         }
       }
   ```



-- 
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: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to