concat
After completion of the original upstream the elements of the given source will be emitted.
Signature¶
Description¶
After completion of the original upstream the elements of the given source will be emitted.
Both streams will be materialized together.
Note
The concat
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 concatLazy
Example¶
source
val sourceA = Source(List(1, 2, 3, 4))
val sourceB = Source(List(10, 20, 30, 40))
sourceA.concat(sourceB).runWith(Sink.foreach(println))
// prints 1, 2, 3, 4, 10, 20, 30, 40
sourceimport org.apache.pekko.stream.javadsl.Keep;
import org.apache.pekko.stream.javadsl.Source;
import org.apache.pekko.stream.javadsl.Sink;
import java.util.*;
Source<Integer, NotUsed> sourceA = Source.from(Arrays.asList(1, 2, 3, 4));
Source<Integer, NotUsed> sourceB = Source.from(Arrays.asList(10, 20, 30, 40));
sourceA.concat(sourceB).runForeach(System.out::println, system);
// prints 1, 2, 3, 4, 10, 20, 30, 40
Reactive Streams semantics¶
emits when the current stream has an element available; if the current input completes, it tries the next one
backpressures when downstream backpressures
completes when all upstreams complete
1.1.3