简体   繁体   中英

Reactor's Flux.combineLatest() with Flux and Mono

Could someone explain me why does it behave this way?

Flux.combineLatest(
    Tuples::fromArray,
    Flux.just(1, 2, 3),
    Mono.just("x"))
.collectList()
.block();
// [{3, "x"}]

Flux.combineLatest(
    Tuples::fromArray,
    Mono.just("x"),
    Flux.just(1, 2, 3))
.collectList()
.block();
// [{"x", 1}, {"x", 2}, {"x", 3}]

And is it possible to make it agnostic to arguments order (I expect option 2 to be a correct one)?

Since every value in just is readily available, there is a form of optimization that can immediately iterates through the elements. In the first snippet, the 3 element just is the first that gets subscribed to and that optimisation kicks in, making it look like the whole sequence has already completed by the time the second Flux is subscribed to, hence the result you see.

To deactivate that optimisation, you can chain in a .hide() and it should produce the same result as in case 2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM