Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.flowable;
import java.util.Objects;
import java.util.concurrent.atomic.*;
import org.reactivestreams.*;
import io.reactivex.rxjava3.annotations.*;
import io.reactivex.rxjava3.core.*;
import io.reactivex.rxjava3.exceptions.Exceptions;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.internal.operators.flowable.FlowableMap.MapSubscriber;
import io.reactivex.rxjava3.internal.subscriptions.*;
import io.reactivex.rxjava3.internal.util.*;
import io.reactivex.rxjava3.operators.SpscLinkedArrayQueue;
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
/**
* Combines the latest values from multiple sources through a function.
*
* @param the value type of the sources
* @param the result type
*/
public final class FlowableCombineLatest
extends Flowable {
@Nullable
final Publisher extends T>[] array;
@Nullable
final Iterable extends Publisher extends T>> iterable;
final Function super Object[], ? extends R> combiner;
final int bufferSize;
final boolean delayErrors;
public FlowableCombineLatest(@NonNull Publisher extends T>[] array,
@NonNull Function super Object[], ? extends R> combiner,
int bufferSize, boolean delayErrors) {
this.array = array;
this.iterable = null;
this.combiner = combiner;
this.bufferSize = bufferSize;
this.delayErrors = delayErrors;
}
public FlowableCombineLatest(@NonNull Iterable extends Publisher extends T>> iterable,
@NonNull Function super Object[], ? extends R> combiner,
int bufferSize, boolean delayErrors) {
this.array = null;
this.iterable = iterable;
this.combiner = combiner;
this.bufferSize = bufferSize;
this.delayErrors = delayErrors;
}
@SuppressWarnings("unchecked")
@Override
public void subscribeActual(Subscriber super R> s) {
Publisher extends T>[] sources = array;
int count;
if (sources == null) {
count = 0;
sources = new Publisher[8];
try {
for (Publisher extends T> p : iterable) {
if (count == sources.length) {
Publisher extends T>[] b = new Publisher[count + (count >> 2)];
System.arraycopy(sources, 0, b, 0, count);
sources = b;
}
sources[count++] = Objects.requireNonNull(p, "The Iterator returned a null Publisher");
}
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
EmptySubscription.error(ex, s);
return;
}
} else {
count = sources.length;
}
if (count == 0) {
EmptySubscription.complete(s);
return;
}
if (count == 1) {
sources[0].subscribe(new MapSubscriber<>(s, new SingletonArrayFunc()));
return;
}
CombineLatestCoordinator coordinator =
new CombineLatestCoordinator<>(s, combiner, count, bufferSize, delayErrors);
s.onSubscribe(coordinator);
coordinator.subscribe(sources, count);
}
static final class CombineLatestCoordinator
extends BasicIntQueueSubscription {
private static final long serialVersionUID = -5082275438355852221L;
final Subscriber super R> downstream;
final Function super Object[], ? extends R> combiner;
final CombineLatestInnerSubscriber[] subscribers;
final SpscLinkedArrayQueue