prependLazy
Prepends the given source to the flow, consuming it until completion before the original source is consumed.
Signature
Source.prepend
Source.prepend
Flow.prepend
Flow.prepend
Description
Prepends the given source to the flow, consuming it until completion before the original source is consumed.
Both streams will be materialized together, however, the original stream will be pulled for the first time only after the prepended upstream was completed. (In contrast, @ref(prepend)[prepend.md], introduces single-element buffers after both, original and given sources so that the original source is also pulled once immediately.)
If materialized values needs to be collected prependLazyMat
is available.
See also prepend which is detached.
Example
- Scala
-
source
val ladies = Source(List("Emma", "Emily")) val gentlemen = Source(List("Liam", "William")) gentlemen.prependLazy(ladies).runWith(Sink.foreach(println)) // this will print "Emma", "Emily", "Liam", "William"
- Java
-
source
import org.apache.pekko.stream.javadsl.Keep; import org.apache.pekko.stream.javadsl.Source; import org.apache.pekko.stream.javadsl.Sink; import java.util.*;
Reactive Streams semantics
emits when the given stream has an element available; if the given input completes, it tries the current one
backpressures when downstream backpressures
completes when all upstreams complete