He-Pin commented on code in PR #1775: URL: https://github.com/apache/pekko/pull/1775#discussion_r1966687328
########## 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: I think the empty case should not be that common, or we can remove the `maybeEmpty` test and let it left in a `_ =>` case , but that way, we need to keep the changes in `getValuePresentedSource(source)` in sync with here. what do you think -- 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