concatLazy

After completion of the original upstream the elements of the given source will be emitted.

Fan-in operators

Signature

Source.concatSource.concat Flow.concatFlow.concat

Description

After completion of the original upstream the elements of the given source will be emitted.

Both streams will be materialized together, however, the given stream will be pulled for the first time only after the original upstream was completed. (In contrast, concat, introduces single-element buffers after both, original and given sources so that the given source is also pulled once immediately.)

To defer the materialization of the given source (or to completely avoid its materialization if the original upstream fails or cancels), wrap it into Source.lazySource.

If materialized values needs to be collected concatLazyMat is available.

Example

Scala
sourceval sourceA = Source(List(1, 2, 3, 4))
val sourceB = Source(List(10, 20, 30, 40))

sourceA.concatLazy(sourceB).runWith(Sink.foreach(println))
Java
sourceimport akka.stream.javadsl.Keep;
import akka.stream.javadsl.Source;
import akka.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.concatLazy(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

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.