[英]Iterate over items from a Recator Flux in another Reactor Flux
I have my Flux flux1 and when I iterate over it, I also want to start this Flux again inside of it so I can access all of my items from flux1 while iterating over the items from flux1.我有我的 Flux Flux1,当我迭代它时,我还想在其中再次启动这个 Flux,这样我就可以从 Flux1 访问我的所有项目,同时迭代来自 Flux1 的项目。 Basically doing this but with Flux:基本上这样做,但使用通量:
for(item in flux1){
for(item2 in flux1){
//xxxxx
}
}
Thank you谢谢
One possible solution would be to have a nested flatmap
, like this:一种可能的解决方案是使用嵌套的flatmap
,如下所示:
Flux<String> flux = Flux.just("a", "b", "c");
flux.flatMap(item -> flux.flatMap(item2 ->
doSomethingAsync(item, item2).doOnNext(e -> log.info("doSomethingAsync({}, {});", item, item2))))
Prints:印刷:
doSomethingAsync(a, a);
doSomethingAsync(a, b);
doSomethingAsync(a, c);
doSomethingAsync(b, a);
doSomethingAsync(b, b);
doSomethingAsync(b, c);
doSomethingAsync(c, a);
doSomethingAsync(c, b);
doSomethingAsync(c, c);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.