【发布时间】:2023-01-10 23:42:58
【问题描述】:
我已经在 reactor 上玩了一段时间了,但我仍然需要得到一些东西。
这段代码
Flux.range(1, 1000)
.delayElements(Duration.ofNanos(1))
.map(integer -> integer + 1)
.subscribe(System.out::println);
System.out.println("after");
退货:
after
2
3
4
预期作为订阅状态的文档:this will immediately return control to the calling thread.
那么,为什么是这段代码:
Flux.range(1, 1000)
.map(integer -> integer + 1)
.subscribe(System.out::println);
回报
1
2
...
1000
1001
after
我永远无法弄清楚subscribe 何时会阻塞,这在编写批处理时非常烦人。
如果有人有答案,那将是惊人的
【问题讨论】:
标签: java asynchronous reactive-programming project-reactor