rx.internal.operators.OnSubscribeMulticastSelector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxjava-core Show documentation
Show all versions of rxjava-core Show documentation
rxjava-core developed by Netflix
/**
* Copyright 2014 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 rx.Observable;
import rx.Observable.OnSubscribe;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Action1;
import rx.functions.Func0;
import rx.functions.Func1;
import rx.observables.ConnectableObservable;
import rx.observers.SafeSubscriber;
import rx.subjects.Subject;
/**
* Returns an observable sequence that contains the elements of a sequence
* produced by multicasting the source sequence within a selector function.
*
* @see MSDN: Observable.Multicast
*
* @param the input value type
* @param the intermediate type
* @param the result type
*/
public final class OnSubscribeMulticastSelector implements OnSubscribe {
final Observable extends TInput> source;
final Func0 extends Subject super TInput, ? extends TIntermediate>> subjectFactory;
final Func1 super Observable, ? extends Observable> resultSelector;
public OnSubscribeMulticastSelector(Observable extends TInput> source,
Func0 extends Subject super TInput, ? extends TIntermediate>> subjectFactory,
Func1 super Observable, ? extends Observable> resultSelector) {
this.source = source;
this.subjectFactory = subjectFactory;
this.resultSelector = resultSelector;
}
@Override
public void call(Subscriber super TResult> child) {
Observable observable;
ConnectableObservable connectable;
try {
Subject super TInput, ? extends TIntermediate> subject = subjectFactory.call();
connectable = new OperatorMulticast(source, subject);
observable = resultSelector.call(connectable);
} catch (Throwable t) {
child.onError(t);
return;
}
final SafeSubscriber s = new SafeSubscriber(child);
observable.unsafeSubscribe(s);
connectable.connect(new Action1() {
@Override
public void call(Subscription t1) {
s.add(t1);
}
});
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy