io.reactivex.rxjava3.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 redisson-all Show documentation
Show all versions of redisson-all Show documentation
Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC
/*
* 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.rxjava3.internal.operators.observable;
import java.util.Objects;
import java.util.concurrent.atomic.*;
import io.reactivex.rxjava3.core.*;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.exceptions.Exceptions;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.internal.disposables.*;
import io.reactivex.rxjava3.internal.util.AtomicThrowable;
import io.reactivex.rxjava3.operators.SpscLinkedArrayQueue;
public final class ObservableCombineLatest extends Observable {
final ObservableSource extends T>[] sources;
final Iterable extends ObservableSource extends T>> sourcesIterable;
final Function super Object[], ? extends R> combiner;
final int bufferSize;
final boolean delayError;
public ObservableCombineLatest(ObservableSource extends T>[] sources,
Iterable extends ObservableSource extends T>> sourcesIterable,
Function super Object[], ? extends R> 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 super R> observer) {
ObservableSource extends T>[] sources = this.sources;
int count = 0;
if (sources == null) {
sources = new ObservableSource[8];
try {
for (ObservableSource extends T> p : sourcesIterable) {
if (count == sources.length) {
ObservableSource extends T>[] b = new ObservableSource[count + (count >> 2)];
System.arraycopy(sources, 0, b, 0, count);
sources = b;
}
sources[count++] = Objects.requireNonNull(p, "The Iterator returned a null ObservableSource");
}
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
EmptyDisposable.error(ex, observer);
return;
}
} 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 super R> downstream;
final Function super Object[], ? extends R> combiner;
final CombinerObserver[] observers;
Object[] latest;
final SpscLinkedArrayQueue
© 2015 - 2025 Weber Informatics LLC | Privacy Policy