rx.internal.operators.OperatorSkipUntil 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 java.util.concurrent.atomic.AtomicBoolean;
import rx.Observable;
import rx.Observable.Operator;
import rx.Subscriber;
import rx.observers.SerializedSubscriber;
/**
* Skip elements from the source Observable until the secondary
* observable fires an element.
*
* If the secondary Observable fires no elements, the primary won't fire any elements.
*
* @see MSDN: Observable.SkipUntil
*
* @param the source and result value type
* @param element type of the signalling observable
*/
public final class OperatorSkipUntil implements Operator {
final Observable other;
public OperatorSkipUntil(Observable other) {
this.other = other;
}
@Override
public Subscriber super T> call(Subscriber super T> child) {
final SerializedSubscriber s = new SerializedSubscriber(child);
final AtomicBoolean gate = new AtomicBoolean();
// u needs to unsubscribe from other independently of child
Subscriber u = new Subscriber() {
@Override
public void onNext(U t) {
gate.set(true);
unsubscribe();
}
@Override
public void onError(Throwable e) {
s.onError(e);
s.unsubscribe();
}
@Override
public void onCompleted() {
unsubscribe();
}
};
child.add(u);
other.unsafeSubscribe(u);
return new Subscriber(child) {
@Override
public void onNext(T t) {
if (gate.get()) {
s.onNext(t);
}
}
@Override
public void onError(Throwable e) {
s.onError(e);
unsubscribe();
}
@Override
public void onCompleted() {
s.onCompleted();
unsubscribe();
}
};
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy