
reactor.core.publisher.MonoWhen 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) 2017-2021 VMware Inc. or its affiliates, All Rights Reserved.
*
* 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
*
* https://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 reactor.core.publisher;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.stream.Stream;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscription;
import reactor.core.CoreSubscriber;
import reactor.core.Exceptions;
import reactor.core.Scannable;
import reactor.util.annotation.Nullable;
import reactor.util.context.Context;
/**
* Waits for all Mono sources to produce a value or terminate, and if all of them produced
* a value, emit a Tuples of those values; otherwise terminate.
*/
final class MonoWhen extends Mono implements SourceProducer {
final boolean delayError;
final Publisher>[] sources;
final Iterable extends Publisher>> sourcesIterable;
MonoWhen(boolean delayError, Publisher>... sources) {
this.delayError = delayError;
this.sources = Objects.requireNonNull(sources, "sources");
this.sourcesIterable = null;
}
MonoWhen(boolean delayError, Iterable extends Publisher>> sourcesIterable) {
this.delayError = delayError;
this.sources = null;
this.sourcesIterable = Objects.requireNonNull(sourcesIterable, "sourcesIterable");
}
@SuppressWarnings("unchecked")
@Nullable
Mono whenAdditionalSource(Publisher> source) {
Publisher[] oldSources = sources;
if (oldSources != null) {
int oldLen = oldSources.length;
Publisher>[] newSources = new Publisher[oldLen + 1];
System.arraycopy(oldSources, 0, newSources, 0, oldLen);
newSources[oldLen] = source;
return new MonoWhen(delayError, newSources);
}
return null;
}
@SuppressWarnings("unchecked")
@Override
public void subscribe(CoreSubscriber super Void> actual) {
Publisher>[] a;
int n = 0;
if (sources != null) {
a = sources;
n = a.length;
}
else {
a = new Publisher[8];
for (Publisher> m : sourcesIterable) {
if (n == a.length) {
Publisher>[] b = new Publisher[n + (n >> 2)];
System.arraycopy(a, 0, b, 0, n);
a = b;
}
a[n++] = m;
}
}
if (n == 0) {
Operators.complete(actual);
return;
}
WhenCoordinator parent = new WhenCoordinator(actual, n, delayError);
actual.onSubscribe(parent);
parent.subscribe(a);
}
@Override
public Object scanUnsafe(Attr key) {
if (key == Attr.DELAY_ERROR) return delayError;
if (key == Attr.RUN_STYLE) return Attr.RunStyle.SYNC;
return null;
}
static final class WhenCoordinator extends Operators.MonoSubscriber
© 2015 - 2025 Weber Informatics LLC | Privacy Policy