初学Reactor一个奇怪的问题
- 初学在学习Reactor的过程中,一个奇怪的问题
第一个doOnNext窥视流打印出了内容,第二个doOnNext就没有打印出任何东西求解
StepVerifier.create(
Flux.just("flux", "mono")
.flatMap(s -> Flux.fromArray(s.split("\\s*")) // 1
.delayElements(Duration.ofMillis(100))) // 2
.doOnNext(System.out::print)) // 3
.expectNextCount(8) // 4
.verifyComplete();
// fmlounox
System.out.println();
Flux.just("flux", "mono")
.flatMap(s -> Flux.fromArray(s.split("\\s*"))
.delayElements(Duration.ofMillis(100)))
.doOnNext(System.out::print);
// 什么也没输出
所用Reactor版本:
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.2.8.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<version>3.2.8.RELEASE</version>
<scope>test</scope>
</dependency>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
响应式数据流在被订阅之前,声明的操作不会被执行
第一个被
StepVerifier.create
调用后被订阅了,而第二个没有被订阅。可以调用
subscribe
方法来手动订阅它由于delayElements添加了延迟,直接放在main方法内的话你可能还需要在后面添加一个
Thread.sleep(800)
才能看到完整的输出。