hu.akarnokd.rxjava2.parallel.ParallelFlatMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxjava2-extensions Show documentation
Show all versions of rxjava2-extensions Show documentation
rxjava2-extensions developed by David Karnok
/*
* Copyright 2016 David Karnok
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hu.akarnokd.rxjava2.parallel;
import io.reactivex.functions.Function;
import org.reactivestreams.*;
import io.reactivex.internal.operators.flowable.FlowableFlatMap;
/**
* Flattens the generated Publishers on each rail.
*
* @param the input value type
* @param the output value type
*/
final class ParallelFlatMap extends ParallelFlowable {
final ParallelFlowable source;
final Function super T, ? extends Publisher extends R>> mapper;
final boolean delayError;
final int maxConcurrency;
final int prefetch;
ParallelFlatMap(
ParallelFlowable source,
Function super T, ? extends Publisher extends R>> mapper,
boolean delayError,
int maxConcurrency,
int prefetch) {
this.source = source;
this.mapper = mapper;
this.delayError = delayError;
this.maxConcurrency = maxConcurrency;
this.prefetch = prefetch;
}
@Override
public int parallelism() {
return source.parallelism();
}
@Override
public void subscribe(Subscriber super R>[] subscribers) {
if (!validate(subscribers)) {
return;
}
int n = subscribers.length;
@SuppressWarnings("unchecked")
final Subscriber[] parents = new Subscriber[n];
// FIXME cheat until we have support from RxJava2 internals
Publisher p = new Publisher() {
int i;
@SuppressWarnings("unchecked")
@Override
public void subscribe(Subscriber super T> s) {
parents[i++] = (Subscriber)s;
}
};
FlowableFlatMap op = new FlowableFlatMap(p, mapper, delayError, maxConcurrency, prefetch);
for (int i = 0; i < n; i++) {
op.subscribe(subscribers[i]);
// FIXME needs a FlatMap subscriber
// parents[i] = FlowableFlatMap.createSubscriber(s, mapper, delayError, maxConcurrency, prefetch);
}
source.subscribe(parents);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy