反应堆上的通量操作会按顺序发生吗?
如果我在通量上有两个平面图,它们将始终按顺序执行
Flux.just(1,2,3,4)
.flatMap(...)
.flatMap(...) // Will this always execute 2nd?
If I have two flatmaps on a flux will the they always execute in sequence
Flux.just(1,2,3,4)
.flatMap(...)
.flatMap(...) // Will this always execute 2nd?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于你到底想表达什么——具体细节在这里很重要。
对于任何给定元素,答案是肯定的 - 它将由第一个 flatMap 调用处理,然后由第二个 flatMap 调用处理该 flatMap 调用的结果。回想一下,reactor 中的操作符与普通的 Java 流类似,是链式的——因此没有明智的方法可以让它们不按顺序操作。
但对于所有元素来说,不会 - 因为它不会处理所有 4 个元素的第一个 flatMap 调用,然后处理所有 4 个元素的第二个 flatMap 调用 - 每个元素都是独立处理的。当您认为 Flux 类似于可能没有尽头的元素流,而不是定义的有界集合时,如果它不这样做就没有多大意义。
It depends on what exactly you mean - specifics are important here.
For any given element the answer is yes - it will be processed by the first flatMap call, then the results of that flatMap call processed by the second flatMap call. Recall that operators in reactor, similar to vanilla Java streams, are chained - so there's no sensible way they could ever operate out of sequence.
For all elements in total though, no - as in it won't process the first flatMap call for all 4 elements, then process the second flatMap call for all 4 elements - each element is treated independently. When you consider that a Flux is analogous to a stream of elements that may have no end, rather than a defined, bounded collection, it wouldn't make much sense if it didn't behave this way.
让我们考虑这些小例子:
我们可以说操作员按照元素进入的顺序处理元素。
Let's consider these small examples :
We can say an operator process the elements in the order they came in.