Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableFromObservable.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.flowable;
15
16 import org.reactivestreams.*;
17
18 import io.reactivex.rxjava3.core.*;
19 import io.reactivex.rxjava3.disposables.Disposable;
20
21 public final class FlowableFromObservable<T> extends Flowable<T> {
22
23 private final ObservableSource<T> upstream;
24
25 public FlowableFromObservable(ObservableSource<T> upstream) {
26 this.upstream = upstream;
27 }
28
29 @Override
30 protected void subscribeActual(Subscriber<? super T> s) {
31 upstream.subscribe(new SubscriberObserver<>(s));
32 }
33
34 static final class SubscriberObserver<T> implements Observer<T>, Subscription {
35
36 final Subscriber<? super T> downstream;
37
38 Disposable upstream;
39
40 SubscriberObserver(Subscriber<? super T> s) {
41 this.downstream = s;
42 }
43
44 @Override
45 public void onComplete() {
46 downstream.onComplete();
47 }
48
49 @Override
50 public void onError(Throwable e) {
51 downstream.onError(e);
52 }
53
54 @Override
55 public void onNext(T value) {
56 downstream.onNext(value);
57 }
58
59 @Override
60 public void onSubscribe(Disposable d) {
61 this.upstream = d;
62 downstream.onSubscribe(this);
63 }
64
65 @Override public void cancel() {
66 upstream.dispose();
67 }
68
69 @Override
70 public void request(long n) {
71 // no backpressure so nothing we can do about this
72 }
73 }
74 }