trap
trap

Reputation: 2640

How to create Flux from Mono

I have a Mono A. The Object A contains two lists. I want to create direct two Flux. Is this possible without block()?

Mono<A> a = ... ;

Flux<AList1> a1 =  Flux.fromIterable(a.block().getList1());

Upvotes: 21

Views: 26737

Answers (1)

mroman
mroman

Reputation: 1678

Use Mono.flatMapMany() method:

    Flux flux1 = mono.map(A::getList1).flatMapMany(Flux::fromIterable);
    Flux flux2 = mono.map(A::getList2).flatMapMany(Flux::fromIterable);

Upvotes: 39

Related Questions