Debian Codegraph @

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