Source.repeat
Stream a single object repeatedly.
Signature
Description
This source emits a single element repeatedly. It never completes, if you want the stream to be finite you will need to limit it by combining with another operator
See also:
single
Stream a single object once.tick
A periodical repetition of an arbitrary object.cycle
Stream iterator in cycled manner.
Example
This example prints the first 4 elements emitted by Source.repeat
.
- Scala
-
source
val source: Source[Int, NotUsed] = Source.repeat(42) val f = source.take(4).runWith(Sink.foreach(println)) // 42 // 42 // 42 // 42
- Java
-
source
Source<Integer, NotUsed> source = Source.repeat(42); CompletionStage<Done> f = source.take(4).runWith(Sink.foreach(System.out::println), system); // 42 // 42 // 42 // 42
Reactive Streams semantics
emits the same value repeatedly when there is demand
completes never