pjfanning commented on code in PR #1775: URL: https://github.com/apache/pekko/pull/1775#discussion_r1966510728
########## stream/src/main/scala/org/apache/pekko/stream/impl/fusing/Ops.scala: ########## @@ -2171,14 +2177,29 @@ private[pekko] object TakeWithin { if (maximumRetries < 0 || attempt < maximumRetries) { pf.applyOrElse(ex, NotApplied) match { case _: NotApplied.type => failStage(ex) - case source: Graph[SourceShape[T] @unchecked, M @unchecked] if TraversalBuilder.isEmptySource(source) => - completeStage() - case other: Graph[SourceShape[T] @unchecked, M @unchecked] => - TraversalBuilder.getSingleSource(other) match { - case OptionVal.Some(singleSource) => - emit(out, singleSource.elem.asInstanceOf[T], () => completeStage()) + case source: Graph[SourceShape[T] @unchecked, M @unchecked] => + TraversalBuilder.getValuePresentedSource(source) match { + case OptionVal.Some(graph) => graph match { + case singleSource: SingleSource[T @unchecked] => emit(out, singleSource.elem, () => completeStage()) + case failed: FailedSource[T @unchecked] => failStage(failed.failure) + case futureSource: FutureSource[T @unchecked] => futureSource.future.value match { + case Some(Success(elem)) => emit(out, elem, () => completeStage()) + case Some(Failure(ex)) => failStage(ex) + case None => + switchTo(source) + attempt += 1 + } + case iterableSource: IterableSource[T @unchecked] => + emitMultiple(out, iterableSource.elements, () => completeStage()) + case javaStreamSource: JavaStreamSource[T @unchecked, _] => + emitMultiple(out, javaStreamSource.open().iterator(), () => completeStage()) + case maybeEmpty if TraversalBuilder.isEmptySource(maybeEmpty) => completeStage() Review Comment: Is this going to be slower than the old code? Old code called `TraversalBuilder.isEmptySource(source)` before calling `TraversalBuilder.getSingleSource`. The new code calls `TraversalBuilder.getValuePresentedSource` before checking `TraversalBuilder.isEmptySource(source)` . -- 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