Jam*_*der 4 project-reactor spring-webflux
反应堆的新手,试图理解Mono.flatMapMany
并Mono.flatMapIterable
经常处理包含集合的对象的 Mono。
有什么区别:
Mono.just(List.of("one", "two", "three")).log().flatMapMany(Flux::fromIterable).subscribe(System.out::println);
Mono.just(List.of("one", "two", "three")).log().flatMapIterable(l -> l).subscribe(System.out::println);
Run Code Online (Sandbox Code Playgroud)
我什么时候使用每种方法?
谢谢
Mono#flatMapMany
是一个通用的一对多运算符。
Mono#flatMapIterable
是一个特殊的运算符,用于将表示为的项目“展平”Iterable<T>
为 的反应流T
。
Mono#flatMapIterable
尽可能使用(映射器可以返回 Iterable)因为它是优化的,Mono#flatMapMany
当你的映射器返回一个Publisher
项目时使用。
归档时间: |
|
查看次数: |
3742 次 |
最近记录: |