Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/parallel/ParallelConcatMap.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.internal.operators.parallel;
15
16 import org.reactivestreams.*;
17
18 import io.reactivex.rxjava3.functions.Function;
19 import io.reactivex.rxjava3.internal.operators.flowable.FlowableConcatMap;
20 import io.reactivex.rxjava3.internal.util.ErrorMode;
21 import io.reactivex.rxjava3.parallel.ParallelFlowable;
22 import io.reactivex.rxjava3.plugins.RxJavaPlugins;
23
24 import java.util.Objects;
25
26 /**
27 * Concatenates the generated Publishers on each rail.
28 *
29 * @param <T> the input value type
30 * @param <R> the output value type
31 */
32 public final class ParallelConcatMap<T, R> extends ParallelFlowable<R> {
33
34 final ParallelFlowable<T> source;
35
36 final Function<? super T, ? extends Publisher<? extends R>> mapper;
37
38 final int prefetch;
39
40 final ErrorMode errorMode;
41
42 public ParallelConcatMap(
43 ParallelFlowable<T> source,
44 Function<? super T, ? extends Publisher<? extends R>> mapper,
45 int prefetch, ErrorMode errorMode) {
46 this.source = source;
47 this.mapper = Objects.requireNonNull(mapper, "mapper");
48 this.prefetch = prefetch;
49 this.errorMode = Objects.requireNonNull(errorMode, "errorMode");
50 }
51
52 @Override
53 public int parallelism() {
54 return source.parallelism();
55 }
56
57 @Override
58 public void subscribe(Subscriber<? super R>[] subscribers) {
59 subscribers = RxJavaPlugins.onSubscribe(this, subscribers);
60
61 if (!validate(subscribers)) {
62 return;
63 }
64
65 int n = subscribers.length;
66
67 @SuppressWarnings("unchecked")
68 final Subscriber<T>[] parents = new Subscriber[n];
69
70 for (int i = 0; i < n; i++) {
71 parents[i] = FlowableConcatMap.subscribe(subscribers[i], mapper, prefetch, errorMode);
72 }
73
74 source.subscribe(parents);
75 }
76 }