mergeAll

Merge multiple sources.

Fan-in operators

Signature

Source.mergeAllSource.mergeAll Flow.mergeAllFlow.mergeAll

Description

Merge multiple sources. Picks elements randomly if all sources has elements ready.

Example

Scala
sourceval sourceA = Source(1 to 3)
val sourceB = Source(4 to 6)
val sourceC = Source(7 to 10)
sourceA.mergeAll(List(sourceB, sourceC), eagerComplete = false).runForeach(println)
// merging is not deterministic, can for example print 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Java
sourceSource<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, 10));
sourceA
    .mergeAll(Arrays.asList(sourceB, sourceC), false)
    .runForeach(System.out::println, system);
// merging is not deterministic, can for example print 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Reactive Streams semantics

emits when one of the inputs has an element available

backpressures when downstream backpressures

completes when all upstreams complete (This behavior is changeable to completing when any upstream completes by setting eagerComplete=true.)

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.