io.reactivex.rxjava3.internal.operators.flowable.FlowableWithLatestFromMany 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.flowable;
import java.util.Arrays;
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.subscriptions.*;
import io.reactivex.rxjava3.internal.util.*;
import io.reactivex.rxjava3.operators.ConditionalSubscriber;
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
/**
* Combines a main sequence of values with the latest from multiple other sequences via
* a selector function.
*
* @param the main sequence's type
* @param the output type
*/
public final class FlowableWithLatestFromMany extends AbstractFlowableWithUpstream {
@Nullable
final Publisher>[] otherArray;
@Nullable
final Iterable extends Publisher>> otherIterable;
final Function super Object[], R> combiner;
public FlowableWithLatestFromMany(@NonNull Flowable source, @NonNull Publisher>[] otherArray, Function super Object[], R> combiner) {
super(source);
this.otherArray = otherArray;
this.otherIterable = null;
this.combiner = combiner;
}
public FlowableWithLatestFromMany(@NonNull Flowable source, @NonNull Iterable extends Publisher>> otherIterable, @NonNull Function super Object[], R> combiner) {
super(source);
this.otherArray = null;
this.otherIterable = otherIterable;
this.combiner = combiner;
}
@Override
protected void subscribeActual(Subscriber super R> s) {
Publisher>[] others = otherArray;
int n = 0;
if (others == null) {
others = new Publisher[8];
try {
for (Publisher> p : otherIterable) {
if (n == others.length) {
others = Arrays.copyOf(others, n + (n >> 1));
}
others[n++] = p;
}
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
EmptySubscription.error(ex, s);
return;
}
} else {
n = others.length;
}
if (n == 0) {
new FlowableMap<>(source, new SingletonArrayFunc()).subscribeActual(s);
return;
}
WithLatestFromSubscriber parent = new WithLatestFromSubscriber<>(s, combiner, n);
s.onSubscribe(parent);
parent.subscribe(others, n);
source.subscribe(parent);
}
static final class WithLatestFromSubscriber
extends AtomicInteger
implements ConditionalSubscriber, Subscription {
private static final long serialVersionUID = 1577321883966341961L;
final Subscriber super R> downstream;
final Function super Object[], R> combiner;
final WithLatestInnerSubscriber[] subscribers;
final AtomicReferenceArray
© 2015 - 2024 Weber Informatics LLC | Privacy Policy