interleave
Emits a specifiable number of elements from the original source, then from the provided source and repeats.
Signature
Source.interleave
Flow.interleave
Description
Emits a specifiable number of elements from the original source, then from the provided source and repeats. If one source completes the rest of the other stream will be emitted.
Example
- Scala
-
source
import akka.stream.scaladsl.Sink import akka.stream.scaladsl.Source val sourceA = Source(List(1, 2, 3, 4)) val sourceB = Source(List(10, 20, 30, 40)) sourceA.interleave(sourceB, segmentSize = 2).runWith(Sink.foreach(println)) //prints 1, 2, 10, 20, 3, 4, 30, 40
- Java
Reactive Streams semantics
emits when element is available from the currently consumed upstream
backpressures when upstream backpressures
completes when both upstreams have completed