Source.repeat

Stream a single object repeatedly.

Source operators

Signature

Source.repeatSource.repeat

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
sourceval source: Source[Int, NotUsed] = Source.repeat(42)
val f = source.take(4).runWith(Sink.foreach(println))
// 42
// 42
// 42
// 42
Java
sourceSource<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

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.