项目反应堆中的Flatmap,Flatmap序列和辅助图有什么区别?
我从文档中读到flatmap
:
将这种通量异步发出的元素转化为发布者,然后通过合并将这些内部发行商弄平为单个通量,从而使它们交织在一起。
FlatMapSequention
:
将这种通量异步发出的元素转换为发布者,然后将这些内部发行商弄平为单个通量,但按照其源元素的顺序合并。
concatmap
:
将这种通量异步发出的元素转化为发布者,然后将这些内部发行商弄平为单个磁通,并使用串联依次保存顺序。 该操作员有三个维度可以与flatmap和flatmap序列进行比较:
生成内部和订阅:该操作员在生成下一个并订阅下来之前等待一个内部完成。
扁平值的排序:该操作员自然保持与源元素相同的顺序,从而依次从每个源元素中加入Inners。
交错:该操作员不允许不同内部的价值交织(串联)。
flatmap
与其他两个之间的差异是可以理解的,但是我不明白concatmap
和flatmapsequepential
之间的差异。两者之间有任何性能差异吗?我已经读到FlatMapSequention
有一个队列的缓冲区大小,但是我不明白为什么ConcatMap
不需要一个。
I've read from the documentation that flatMap
:
Transform the elements emitted by this Flux asynchronously into Publishers, then flatten these inner publishers into a single Flux through merging, which allow them to interleave.
that flatMapSequential
:
Transform the elements emitted by this Flux asynchronously into Publishers, then flatten these inner publishers into a single Flux, but merge them in the order of their source element.
and that concatMap
:
Transform the elements emitted by this Flux asynchronously into Publishers, then flatten these inner publishers into a single Flux, sequentially and preserving order using concatenation.
There are three dimensions to this operator that can be compared with flatMap and flatMapSequential:
Generation of inners and subscription: this operator waits for one inner to complete before generating the next one and subscribing to it.
Ordering of the flattened values: this operator naturally preserves the same order as the source elements, concatenating the inners from each source element sequentially.
Interleaving: this operator does not let values from different inners interleave (concatenation).
The difference between flatMap
and the other two is pretty understandable, but I don't understand when the difference between concatMap
and flatMapSequential
takes place. Is there any performance difference between the two? I've read that flatMapSequential
has a buffer size for some queue, but I don't understand why concatMap
doesn't need one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
' flatmap 和
flatmapsequepential
 运营商急切地订阅concatmap
 等待每个内部完成对此。让我们看看一个示例:
输出:
如您所见,
flatmap
不能保留原始订购,并且急切地订阅了所有三个元素。另外,请注意,元素3已在元素2之前进行。这是使用
FlatmapSequention
的输出:Flatmapsequential
已急切地订阅了所有三个元素,例如flatsmap
但保留了按订单收到的排队元素的订单。这是使用
ConcatMap
的输出:ConcatMap
 自然地保留与源元素相同的顺序。The
flatMap
andflatMapSequential
operators subscribe eagerly, theconcatMap
waits for each inner completion before generating the next sub-stream and subscribing to it.Let's see an example:
Output:
As you can see,
flatMap
does not preserve original ordering, and has subscribed to all three elements eagerly. Also, notice that element 3 has proceeded before element 2.Here is the output using
flatMapSequential
:flatMapSequential
has subscribed to all three elements eagerly likeflatMap
but preserves the order by queuing elements received out of order.Here is the output using
concatMap
:concatMap
naturally preserves the same order as the source elements.