rx.internal.operators.OperatorWithLatestFromMany Maven / Gradle / Ivy
/**
* Copyright 2014 Netflix, Inc.
*
* 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 rx.internal.operators;
import java.util.Arrays;
import java.util.concurrent.atomic.*;
import rx.*;
import rx.Observable.OnSubscribe;
import rx.exceptions.Exceptions;
import rx.functions.FuncN;
import rx.observers.SerializedSubscriber;
import rx.plugins.RxJavaHooks;
public final class OperatorWithLatestFromMany implements OnSubscribe {
final Observable main;
final Observable>[] others;
final Iterable> othersIterable;
final FuncN combiner;
public OperatorWithLatestFromMany(Observable main, Observable>[] others, Iterable> othersIterable, FuncN combiner) {
this.main = main;
this.others = others;
this.othersIterable = othersIterable;
this.combiner = combiner;
}
@Override
public void call(Subscriber super R> t) {
SerializedSubscriber serial = new SerializedSubscriber(t);
Observable>[] sources;
int n = 0;
if (others != null) {
sources = others;
n = sources.length;
} else {
sources = new Observable[8];
for (Observable> o : othersIterable) {
if (n == sources.length) {
sources = Arrays.copyOf(sources, n + (n >> 2));
}
sources[n++] = o;
}
}
WithLatestMainSubscriber parent = new WithLatestMainSubscriber(t, combiner, n);
serial.add(parent);
for (int i = 0; i < n; i++) {
if (serial.isUnsubscribed()) {
return;
}
WithLatestOtherSubscriber inner = new WithLatestOtherSubscriber(parent, i + 1);
parent.add(inner);
Observable> o = sources[i];
o.unsafeSubscribe(inner);
}
main.unsafeSubscribe(parent);
}
static final class WithLatestMainSubscriber extends Subscriber {
final Subscriber super R> actual;
final FuncN combiner;
final AtomicReferenceArray
© 2015 - 2024 Weber Informatics LLC | Privacy Policy