Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/observable/ObservableSkipUntil.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.internal.operators.observable;
15
16 import io.reactivex.rxjava3.core.*;
17 import io.reactivex.rxjava3.disposables.Disposable;
18 import io.reactivex.rxjava3.internal.disposables.*;
19 import io.reactivex.rxjava3.observers.SerializedObserver;
20
21 public final class ObservableSkipUntil<T, U> extends AbstractObservableWithUpstream<T, T> {
22 final ObservableSource<U> other;
23 public ObservableSkipUntil(ObservableSource<T> source, ObservableSource<U> other) {
24 super(source);
25 this.other = other;
26 }
27
28 @Override
29 public void subscribeActual(Observer<? super T> child) {
30
31 final SerializedObserver<T> serial = new SerializedObserver<>(child);
32
33 final ArrayCompositeDisposable frc = new ArrayCompositeDisposable(2);
34
35 serial.onSubscribe(frc);
36
37 final SkipUntilObserver<T> sus = new SkipUntilObserver<>(serial, frc);
38
39 other.subscribe(new SkipUntil(frc, sus, serial));
40
41 source.subscribe(sus);
42 }
43
44 static final class SkipUntilObserver<T> implements Observer<T> {
45
46 final Observer<? super T> downstream;
47 final ArrayCompositeDisposable frc;
48
49 Disposable upstream;
50
51 volatile boolean notSkipping;
52 boolean notSkippingLocal;
53
54 SkipUntilObserver(Observer<? super T> actual, ArrayCompositeDisposable frc) {
55 this.downstream = actual;
56 this.frc = frc;
57 }
58
59 @Override
60 public void onSubscribe(Disposable d) {
61 if (DisposableHelper.validate(this.upstream, d)) {
62 this.upstream = d;
63 frc.setResource(0, d);
64 }
65 }
66
67 @Override
68 public void onNext(T t) {
69 if (notSkippingLocal) {
70 downstream.onNext(t);
71 } else
72 if (notSkipping) {
73 notSkippingLocal = true;
74 downstream.onNext(t);
75 }
76 }
77
78 @Override
79 public void onError(Throwable t) {
80 frc.dispose();
81 downstream.onError(t);
82 }
83
84 @Override
85 public void onComplete() {
86 frc.dispose();
87 downstream.onComplete();
88 }
89 }
90
91 final class SkipUntil implements Observer<U> {
92 final ArrayCompositeDisposable frc;
93 final SkipUntilObserver<T> sus;
94 final SerializedObserver<T> serial;
95 Disposable upstream;
96
97 SkipUntil(ArrayCompositeDisposable frc, SkipUntilObserver<T> sus, SerializedObserver<T> serial) {
98 this.frc = frc;
99 this.sus = sus;
100 this.serial = serial;
101 }
102
103 @Override
104 public void onSubscribe(Disposable d) {
105 if (DisposableHelper.validate(this.upstream, d)) {
106 this.upstream = d;
107 frc.setResource(1, d);
108 }
109 }
110
111 @Override
112 public void onNext(U t) {
113 upstream.dispose();
114 sus.notSkipping = true;
115 }
116
117 @Override
118 public void onError(Throwable t) {
119 frc.dispose();
120 serial.onError(t);
121 }
122
123 @Override
124 public void onComplete() {
125 sus.notSkipping = true;
126 }
127 }
128 }