interleave
Emits a specifiable number of elements from the original source, then from the provided source and repeats.
Signature
Source.interleave
Source.interleave
Flow.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 org.apache.pekko import pekko.stream.scaladsl.Sink import pekko.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
-
source
import 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, 4)); Source<Integer, NotUsed> sourceB = Source.from(Arrays.asList(10, 20, 30, 40)); sourceA.interleave(sourceB, 2).runForeach(System.out::println, system); // prints 1, 2, 10, 20, 3, 4, 30, 40
Reactive Streams semantics
emits when element is available from the currently consumed upstream
backpressures when upstream backpressures
completes when both upstreams have completed
1.1.2+24-bcd44ee3*