io.reactivex.internal.operators.observable.ObservableCombineLatest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxjava Show documentation
Show all versions of rxjava Show documentation
Reactive Extensions for Java
/**
* Copyright (c) 2016-present, RxJava Contributors.
*
* 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 io.reactivex.internal.operators.observable;
import java.util.concurrent.atomic.*;
import io.reactivex.*;
import io.reactivex.disposables.Disposable;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.functions.Function;
import io.reactivex.internal.disposables.*;
import io.reactivex.internal.functions.ObjectHelper;
import io.reactivex.internal.queue.SpscLinkedArrayQueue;
import io.reactivex.internal.util.AtomicThrowable;
import io.reactivex.plugins.RxJavaPlugins;
public final class ObservableCombineLatest extends Observable {
final ObservableSource[] sources;
final Iterable> sourcesIterable;
final Function combiner;
final int bufferSize;
final boolean delayError;
public ObservableCombineLatest(ObservableSource[] sources,
Iterable> sourcesIterable,
Function combiner, int bufferSize,
boolean delayError) {
this.sources = sources;
this.sourcesIterable = sourcesIterable;
this.combiner = combiner;
this.bufferSize = bufferSize;
this.delayError = delayError;
}
@Override
@SuppressWarnings("unchecked")
public void subscribeActual(Observer observer) {
ObservableSource[] sources = this.sources;
int count = 0;
if (sources == null) {
sources = new Observable[8];
for (ObservableSource p : sourcesIterable) {
if (count == sources.length) {
ObservableSource[] b = new ObservableSource[count + (count >> 2)];
System.arraycopy(sources, 0, b, 0, count);
sources = b;
}
sources[count++] = p;
}
} else {
count = sources.length;
}
if (count == 0) {
EmptyDisposable.complete(observer);
return;
}
LatestCoordinator lc = new LatestCoordinator(observer, combiner, count, bufferSize, delayError);
lc.subscribe(sources);
}
static final class LatestCoordinator extends AtomicInteger implements Disposable {
private static final long serialVersionUID = 8567835998786448817L;
final Observer downstream;
final Function combiner;
final CombinerObserver[] observers;
Object[] latest;
final SpscLinkedArrayQueue