Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/completable/CompletableHide.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.completable;
15
16 import io.reactivex.rxjava3.core.*;
17 import io.reactivex.rxjava3.disposables.Disposable;
18 import io.reactivex.rxjava3.internal.disposables.DisposableHelper;
19
20 /**
21 * Hides the identity of the upstream Completable and its Disposable sent through onSubscribe.
22 */
23 public final class CompletableHide extends Completable {
24
25 final CompletableSource source;
26
27 public CompletableHide(CompletableSource source) {
28 this.source = source;
29 }
30
31 @Override
32 protected void subscribeActual(CompletableObserver observer) {
33 source.subscribe(new HideCompletableObserver(observer));
34 }
35
36 static final class HideCompletableObserver implements CompletableObserver, Disposable {
37
38 final CompletableObserver downstream;
39
40 Disposable upstream;
41
42 HideCompletableObserver(CompletableObserver downstream) {
43 this.downstream = downstream;
44 }
45
46 @Override
47 public void dispose() {
48 upstream.dispose();
49 upstream = DisposableHelper.DISPOSED;
50 }
51
52 @Override
53 public boolean isDisposed() {
54 return upstream.isDisposed();
55 }
56
57 @Override
58 public void onSubscribe(Disposable d) {
59 if (DisposableHelper.validate(this.upstream, d)) {
60 this.upstream = d;
61
62 downstream.onSubscribe(this);
63 }
64 }
65
66 @Override
67 public void onError(Throwable e) {
68 downstream.onError(e);
69 }
70
71 @Override
72 public void onComplete() {
73 downstream.onComplete();
74 }
75 }
76 }