concatAllLazy

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

Fan-in operators

Signature

Source.concatAllLazySource.concatAllLazy Flow.concatAllLazyFlow.concatAllLazy

Description

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

Both streams will be materialized together, however, the given streams will be pulled for the first time only after the original upstream was completed.

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

Example

Scala
sourceval sourceA = Source(List(1, 2, 3))
val sourceB = Source(List(4, 5, 6))
val sourceC = Source(List(7, 8, 9))
sourceA
  .concatAllLazy(sourceB, sourceC)
  .fold(new StringJoiner(","))((joiner, input) => joiner.add(String.valueOf(input)))
  .runWith(Sink.foreach(println))
// prints 1,2,3,4,5,6,7,8,9
Java
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));
Source<Integer, NotUsed> sourceB = Source.from(Arrays.asList(4, 5, 6));
Source<Integer, NotUsed> sourceC = Source.from(Arrays.asList(7, 8, 9));
sourceA
    .concatAllLazy(sourceB, sourceC)
    .fold(new StringJoiner(","), (joiner, input) -> joiner.add(String.valueOf(input)))
    .runForeach(System.out::println, system);
// prints 1,2,3,4,5,6,7,8,9

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