Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/completable/CompletableFromPublisher.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 org.reactivestreams.*;
17
18 import io.reactivex.rxjava3.core.*;
19 import io.reactivex.rxjava3.disposables.Disposable;
20 import io.reactivex.rxjava3.internal.subscriptions.SubscriptionHelper;
21
22 public final class CompletableFromPublisher<T> extends Completable {
23
24 final Publisher<T> flowable;
25
26 public CompletableFromPublisher(Publisher<T> flowable) {
27 this.flowable = flowable;
28 }
29
30 @Override
31 protected void subscribeActual(final CompletableObserver downstream) {
32 flowable.subscribe(new FromPublisherSubscriber<>(downstream));
33 }
34
35 static final class FromPublisherSubscriber<T> implements FlowableSubscriber<T>, Disposable {
36
37 final CompletableObserver downstream;
38
39 Subscription upstream;
40
41 FromPublisherSubscriber(CompletableObserver downstream) {
42 this.downstream = downstream;
43 }
44
45 @Override
46 public void onSubscribe(Subscription s) {
47 if (SubscriptionHelper.validate(this.upstream, s)) {
48 this.upstream = s;
49
50 downstream.onSubscribe(this);
51
52 s.request(Long.MAX_VALUE);
53 }
54 }
55
56 @Override
57 public void onNext(T t) {
58 // ignored
59 }
60
61 @Override
62 public void onError(Throwable t) {
63 downstream.onError(t);
64 }
65
66 @Override
67 public void onComplete() {
68 downstream.onComplete();
69 }
70
71 @Override
72 public void dispose() {
73 upstream.cancel();
74 upstream = SubscriptionHelper.CANCELLED;
75 }
76
77 @Override
78 public boolean isDisposed() {
79 return upstream == SubscriptionHelper.CANCELLED;
80 }
81 }
82
83 }