Proper way to create a Flux from a list of Mono's

Answer #1 100 %

I believe you can use concat() instead:

/**
 * Concatenate all sources provided as a vararg, forwarding elements emitted by the
 * sources downstream.
 * 

* Concatenation is achieved by sequentially subscribing to the first source then * waiting for it to complete before subscribing to the next, and so on until the * last source completes. Any error interrupts the sequence immediately and is * forwarded downstream. *

* *

* @param sources The {@link Publisher} of {@link Publisher} to concat * @param The type of values in both source and output sequences * * @return a new {@link Flux} concatenating all source sequences */ @SafeVarargs public static Flux concat(Publisher... sources) {

Or merge():

/**
 * Merge data from {@link Publisher} sequences contained in an array / vararg
 * into an interleaved merged sequence. Unlike {@link #concat(Publisher) concat},
 * sources are subscribed to eagerly.
 * 

* *

* Note that merge is tailored to work with asynchronous sources or finite sources. When dealing with * an infinite source that doesn't already publish on a dedicated Scheduler, you must isolate that source * in its own Scheduler, as merge would otherwise attempt to drain it before subscribing to * another source. * * @param sources the array of {@link Publisher} sources to merge * @param The source type of the data sequence * * @return a merged {@link Flux} */ @SafeVarargs public static Flux merge(Publisher... sources) {

You’ll also like:


© 2023 CodeForDev.com -