prepend
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.
The `prepend` operator is for backwards compatibility reasons "detached" and will eagerly
demand an element from both upstreams when the stream is materialized and will then have a
one element buffer for each of the upstreams, this is most often not what you want, instead
use @ref(prependLazy)[prependLazy.md]
If materialized values needs to be collected prependMat
is available.
The prepend
operator is for backwards compatibility reasons “detached” and will eagerly demand an element from both upstreams when the stream is materialized and will then have a one element buffer for each of the upstreams, this is not always what you want, if not, use @ref(prependLazy)[prependLazy.md]
Example
- Scala
-
source
val ladies = Source(List("Emma", "Emily")) val gentlemen = Source(List("Liam", "William")) gentlemen.prepend(ladies).runWith(Sink.foreach(println)) // this will print "Emma", "Emily", "Liam", "William" - Java
-
source
import akka.stream.javadsl.Keep; import akka.stream.javadsl.Source; import akka.stream.javadsl.Sink; import java.util.*; Source<String, NotUsed> ladies = Source.from(Arrays.asList("Emma", "Emily")); Source<String, NotUsed> gentlemen = Source.from(Arrays.asList("Liam", "William")); gentlemen.prepend(ladies).runForeach(System.out::println, system); // this will print "Emma", "Emily", "Liam", "William" Source<String, NotUsed> ladies = Source.from(Arrays.asList("Emma", "Emily")); Source<String, NotUsed> gentlemen = Source.from(Arrays.asList("Liam", "William")); gentlemen.prependLazy(ladies).runForeach(System.out::println, system); // this will print "Emma", "Emily", "Liam", "William"
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