interval is a Project Reactor factory method that creates a Flux emitting incrementing values at a specified duration. Unlike range(), it receives an emission interval instead of starting and ending values. section 11.3.1
Emit five values once per second
Flux<Long> intervalFlux = Flux.interval(Duration.ofSeconds(1)).take(5); The sequence emits 0L, 1L, 2L, 3L, and 4L, then completes. Because interval() has no maximum value, take(5) limits the potentially unending sequence. section 11.3.1
@Test
public void createAFlux_interval() {
Flux<Long> intervalFlux =
Flux.interval(Duration.ofSeconds(1))
.take(5);
StepVerifier.create(intervalFlux)
.expectNext(0L)
.expectNext(1L)
.expectNext(2L)
.expectNext(3L)
.expectNext(4L)
.verifyComplete();
}
View the complete StepVerifier test for a one-second interval producing five incrementing values. section 11.3.1
