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 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));
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

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.