diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala b/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala index 645f1ae89a..3ad2a86a24 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala @@ -558,10 +558,17 @@ class Flow[-In, +Out, +Mat](delegate: scaladsl.Flow[In, Out, Mat]) extends Graph new Flow(delegate.transform(() ⇒ mkStage.create())) /** - * Takes up to `n` elements from the stream and returns a pair containing a strict sequence of the taken element + * Takes up to `n` elements from the stream (less than `n` only if the upstream completes before emitting `n` elements) + * and returns a pair containing a strict sequence of the taken element * and a stream representing the remaining elements. If ''n'' is zero or negative, then this will return a pair * of an empty collection and a stream containing the whole upstream unchanged. * + * In case of an upstream error, depending on the current state + * - the master stream signals the error if less than `n` elements has been seen, and therefore the substream + * has not yet been emitted + * - the tail substream signals the error after the prefix and tail has been emitted by the main stream + * (at that point the main stream has already completed) + * * '''Emits when''' the configured number of prefix elements are available. Emits this prefix, and the rest * as a substream * diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala b/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala index 91467cee3c..96f49c7e69 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala @@ -522,9 +522,16 @@ class Source[+Out, +Mat](delegate: scaladsl.Source[Out, Mat]) extends Graph[Sour new Source(delegate.transform(() ⇒ mkStage.create())) /** - * Takes up to `n` elements from the stream and returns a pair containing a strict sequence of the taken element + * Takes up to `n` elements from the stream (less than `n` only if the upstream completes before emitting `n` elements) + * and returns a pair containing a strict sequence of the taken element * and a stream representing the remaining elements. If ''n'' is zero or negative, then this will return a pair * of an empty collection and a stream containing the whole upstream unchanged. + * + * In case of an upstream error, depending on the current state + * - the master stream signals the error if less than `n` elements has been seen, and therefore the substream + * has not yet been emitted + * - the tail substream signals the error after the prefix and tail has been emitted by the main stream + * (at that point the main stream has already completed) */ def prefixAndTail(n: Int): javadsl.Source[akka.japi.Pair[java.util.List[Out @uncheckedVariance], javadsl.Source[Out @uncheckedVariance, Unit]], Mat] = new Source(delegate.prefixAndTail(n).map { case (taken, tail) ⇒ akka.japi.Pair(taken.asJava, tail.asJava) }) diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala index 5acd5f817e..d476f89652 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala @@ -779,10 +779,17 @@ trait FlowOps[+Out, +Mat] { andThenMat(MaterializingStageFactory(mkStageAndMaterialized)) /** - * Takes up to `n` elements from the stream and returns a pair containing a strict sequence of the taken element + * Takes up to `n` elements from the stream (less than `n` only if the upstream completes before emitting `n` elements) + * and returns a pair containing a strict sequence of the taken element * and a stream representing the remaining elements. If ''n'' is zero or negative, then this will return a pair * of an empty collection and a stream containing the whole upstream unchanged. * + * In case of an upstream error, depending on the current state + * - the master stream signals the error if less than `n` elements has been seen, and therefore the substream + * has not yet been emitted + * - the tail substream signals the error after the prefix and tail has been emitted by the main stream + * (at that point the main stream has already completed) + * * '''Emits when''' the configured number of prefix elements are available. Emits this prefix, and the rest * as a substream *