我正在尝试创建以下链:
DateTimeOffset
因此我需要得到5.但在执行1,2和3,4之前。
代码工作正常,但我想出去
来自Mono<Object1> oneMono = Mono.just("1");
Mono<Object2> twoMono = Mono.just("2");
Mono<Mono<Object5>> resultMono = Mono.zip(oneMono, twoMono, (one, two) -> {
Mono<Object3> threeMono = Mono.just("3");
Mono<Object4> fourMono = Mono.just("4");
return Mono.zip(threeMono, fourMono, (three, four) -> {
return "5";
}
}) // get just Mono<Object5> here?
resultMono.subscribe(mono -> {
mono.subscribe(); // ugly double subscribe() !!
});
和Mono<Mono<Object5>>
到double subscribe
和Mono<Object5>
。
是否存在Zip的模拟flatMap?
答案 0 :(得分:2)
嗯,你已经拥有它了。你只需要使用flatMap:
Mono<String> oneMono = Mono.just("1");
Mono<String> twoMono = Mono.just("2");
Mono.zip(oneMono, twoMono, (one, two) -> {
Mono<String> threeMono = Mono.just("3");
Mono<String> fourMono = Mono.just("4");
return Mono.zip(threeMono, fourMono, (three, four) -> {
return "5";
});
})
.flatMap(stringMono -> stringMono)
.doOnNext(System.out::println)
.subscribe();