我想发出元素,在这些元素中,元素被延迟了一段时间,而没有最初的延迟。
我不能用
Flux.delayElements(Duration)因为它在第一个元素之前延迟了初始延迟,这在我的情况下是不被期望的。
考虑举个例子
Flux.range(1, n)我希望有以下设想:
1延迟2延迟3延迟..。
当前版本的Flux.delayElements的工作方式如下:
延迟1延迟2延迟3 ..。
我现在的解决办法
Flux.interval(
Duration.ZERO,
Duration.ofSeconds(1)
)
// make some call但是它会引发类似于:Spring WebFlux (reactor). Error when zipWith - Could not emit tick due to lack of requests的问题
您能为这种情况提出其他解决方案吗?或者应该提出一些问题,以便在Flux中引入新的方法来解决这个问题?
发布于 2022-05-13 21:03:12
您可以使用Mono.delay()来控制延迟。
@Test
void test() {
var stream = Flux.range(1, 10)
.concatMap(i ->
Mono.delay(Duration.ofSeconds(i))
.thenReturn(i)
)
.log();
StepVerifier.create(stream)
.thenConsumeWhile(rec -> true)
.verifyComplete();
}https://stackoverflow.com/questions/72230641
复制相似问题