Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/observable/ObservableFromCompletable.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.DisposableHelper;
19 import io.reactivex.rxjava3.internal.fuseable.*;
20
21 /**
22 * Wrap a Completable into an Observable.
23 *
24 * @param <T> the value type
25 * @since 3.0.0
26 */
27 public final class ObservableFromCompletable<T> extends Observable<T> implements HasUpstreamCompletableSource {
28
29 final CompletableSource source;
30
31 public ObservableFromCompletable(CompletableSource source) {
32 this.source = source;
33 }
34
35 @Override
36 public CompletableSource source() {
37 return source;
38 }
39
40 @Override
41 protected void subscribeActual(Observer<? super T> observer) {
42 source.subscribe(new FromCompletableObserver<T>(observer));
43 }
44
45 public static final class FromCompletableObserver<T>
46 extends AbstractEmptyQueueFuseable<T>
47 implements CompletableObserver {
48
49 final Observer<? super T> downstream;
50
51 Disposable upstream;
52
53 public FromCompletableObserver(Observer<? super T> downstream) {
54 this.downstream = downstream;
55 }
56
57 @Override
58 public void dispose() {
59 upstream.dispose();
60 upstream = DisposableHelper.DISPOSED;
61 }
62
63 @Override
64 public boolean isDisposed() {
65 return upstream.isDisposed();
66 }
67
68 @Override
69 public void onSubscribe(Disposable d) {
70 if (DisposableHelper.validate(this.upstream, d)) {
71 this.upstream = d;
72
73 downstream.onSubscribe(this);
74 }
75 }
76
77 @Override
78 public void onComplete() {
79 upstream = DisposableHelper.DISPOSED;
80 downstream.onComplete();
81 }
82
83 @Override
84 public void onError(Throwable e) {
85 upstream = DisposableHelper.DISPOSED;
86 downstream.onError(e);
87 }
88 }
89 }