rx.internal.operators.OnSubscribeConcatMap Maven / Gradle / Ivy
/**
* Copyright 2016 Netflix, Inc.
*
* 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 rx.internal.operators;
import java.util.Queue;
import java.util.concurrent.atomic.*;
import rx.*;
import rx.Observable.OnSubscribe;
import rx.exceptions.*;
import rx.functions.Func1;
import rx.internal.producers.ProducerArbiter;
import rx.internal.util.*;
import rx.internal.util.atomic.SpscAtomicArrayQueue;
import rx.internal.util.unsafe.*;
import rx.observers.SerializedSubscriber;
import rx.plugins.RxJavaHooks;
import rx.subscriptions.SerialSubscription;
/**
* Maps a source sequence into Observables and concatenates them in order, subscribing
* to one at a time.
* @param the source value type
* @param the output value type
*
* @since 1.1.2
*/
public final class OnSubscribeConcatMap implements OnSubscribe {
final Observable extends T> source;
final Func1 super T, ? extends Observable extends R>> mapper;
final int prefetch;
/**
* How to handle errors from the main and inner Observables.
* See the constants below.
*/
final int delayErrorMode;
/** Whenever any Observable fires an error, terminate with that error immediately. */
public static final int IMMEDIATE = 0;
/** Whenever the main fires an error, wait until the inner terminates. */
public static final int BOUNDARY = 1;
/** Delay all errors to the very end. */
public static final int END = 2;
public OnSubscribeConcatMap(Observable extends T> source, Func1 super T, ? extends Observable extends R>> mapper, int prefetch,
int delayErrorMode) {
this.source = source;
this.mapper = mapper;
this.prefetch = prefetch;
this.delayErrorMode = delayErrorMode;
}
@Override
public void call(Subscriber super R> child) {
Subscriber super R> s;
if (delayErrorMode == IMMEDIATE) {
s = new SerializedSubscriber(child);
} else {
s = child;
}
final ConcatMapSubscriber parent = new ConcatMapSubscriber(s, mapper, prefetch, delayErrorMode);
child.add(parent);
child.add(parent.inner);
child.setProducer(new Producer() {
@Override
public void request(long n) {
parent.requestMore(n);
}
});
if (!child.isUnsubscribed()) {
source.unsafeSubscribe(parent);
}
}
static final class ConcatMapSubscriber extends Subscriber {
final Subscriber super R> actual;
final Func1 super T, ? extends Observable extends R>> mapper;
final int delayErrorMode;
final ProducerArbiter arbiter;
final Queue
© 2015 - 2024 Weber Informatics LLC | Privacy Policy