/** * Generates and flattens Publishers on each 'rail', optionally delaying errors, * having a total number of simultaneous subscriptions to the inner Publishers and * using the given prefetch amount for the inner Publishers. * * @param <R> the result type * @param mapper the function to map each rail's value into a Publisher * @param delayError should the errors from the main and the inner sources delayed * till everybody terminates? * @param maxConcurrency the maximum number of simultaneous subscriptions to the * generated inner Publishers * @param prefetch the number of items to prefetch from each inner Publisher * * @return the new {@link ParallelFlux} instance */ public final <R> ParallelFlux<R> flatMap(Function<? super T, ? extends Publisher<? extends R>> mapper, boolean delayError, int maxConcurrency, int prefetch) { return onAssembly(new ParallelFlatMap<>(this, mapper, delayError, maxConcurrency, Queues.get(maxConcurrency), prefetch, Queues.get(prefetch))); }
@Test public void parallelism() { ParallelFlux<Integer> source = Flux.range(1, 4).parallel(3); ParallelFlatMap<Integer, Integer> test = new ParallelFlatMap<>(source, i -> Flux.range(1, i), false, 12, Queues.small(), 123, Queues.small()); assertThat(test.parallelism()) .isEqualTo(3) .isEqualTo(source.parallelism()); }
@Test public void scanOperator() throws Exception { ParallelFlux<Integer> source = Flux.range(1, 4).parallel(3); ParallelFlatMap<Integer, Integer> test = new ParallelFlatMap<>(source, i -> Flux.range(1, i), true, 12, Queues.small(), 123, Queues.small()); assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source); assertThat(test.scan(Scannable.Attr.PREFETCH)) .isEqualTo(123) .isNotEqualTo(source.getPrefetch()); assertThat(test.scan(Scannable.Attr.DELAY_ERROR)).isTrue(); }
/** * Generates and flattens Publishers on each 'rail', optionally delaying errors, * having a total number of simultaneous subscriptions to the inner Publishers and * using the given prefetch amount for the inner Publishers. * * @param <R> the result type * @param mapper the function to map each rail's value into a Publisher * @param delayError should the errors from the main and the inner sources delayed * till everybody terminates? * @param maxConcurrency the maximum number of simultaneous subscriptions to the * generated inner Publishers * @param prefetch the number of items to prefetch from each inner Publisher * * @return the new {@link ParallelFlux} instance */ public final <R> ParallelFlux<R> flatMap(Function<? super T, ? extends Publisher<? extends R>> mapper, boolean delayError, int maxConcurrency, int prefetch) { return onAssembly(new ParallelFlatMap<>(this, mapper, delayError, maxConcurrency, Queues.get(maxConcurrency), prefetch, Queues.get(prefetch))); }