我想了解无限流(infinite Stream)和无限Flux(infinite Flux)之间的概念差异(如果有的话)。
为此,我列举了下面这些无限流/Flux的示例:
@Test
public void infinteStream() {
//Prints infinite number of integers
Stream<Integer> infiniteStream = Stream.iterate(0, i -> i+1);
infiniteStream.forEach(System.out::println);
}
@Test
public void infiniteFlux() {
//Prints infinite number of date strings (every second)
Flux<LocalDateTime> localDateTimeFlux = Flux.interval(Duration.ofSeconds(1))
.map(t -> LocalDateTime.now());
localDateTimeFlux.subscribe(t -> System.out.println(t.format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"))));
}
关于这些例子,我有一个问题:是否有类似于Flux的infinteStream()(以及类似于Stream的infinteFlux())的模拟?并且,更一般地说,无限流和Flux之间是否有任何区别?