react 堆新手,试图了解 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);
我什么时候使用每种方法?
谢谢
最佳答案
Mono#flatMapMany
是一个通用的一对多运算符。Mono#flatMapIterable
是一个特殊的运算符,用于“展平”表示为 Iterable<T>
的项目进入 T
的 react 流.
使用 Mono#flatMapIterable
在可能的情况下(映射器可以返回 Iterable),因为它已优化,请使用 Mono#flatMapMany
当您的映射器返回 Publisher
时项。
关于spring-webflux - 我什么时候使用 Mono.flatMapIterable 和 Mono.flapMapMany?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55966358/