Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/operators/maybe/MaybeIgnoreElementCompletable.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.maybe;
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.FuseToMaybe;
20 import io.reactivex.rxjava3.plugins.RxJavaPlugins;
21
22 /**
23 * Turns an onSuccess into an onComplete, onError and onComplete is relayed as is.
24 *
25 * @param <T> the value type
26 */
27 public final class MaybeIgnoreElementCompletable<T> extends Completable implements FuseToMaybe<T> {
28
29 final MaybeSource<T> source;
30
31 public MaybeIgnoreElementCompletable(MaybeSource<T> source) {
32 this.source = source;
33 }
34
35 @Override
36 protected void subscribeActual(CompletableObserver observer) {
37 source.subscribe(new IgnoreMaybeObserver<>(observer));
38 }
39
40 @Override
41 public Maybe<T> fuseToMaybe() {
42 return RxJavaPlugins.onAssembly(new MaybeIgnoreElement<>(source));
43 }
44
45 static final class IgnoreMaybeObserver<T> implements MaybeObserver<T>, Disposable {
46
47 final CompletableObserver downstream;
48
49 Disposable upstream;
50
51 IgnoreMaybeObserver(CompletableObserver downstream) {
52 this.downstream = downstream;
53 }
54
55 @Override
56 public void onSubscribe(Disposable d) {
57 if (DisposableHelper.validate(this.upstream, d)) {
58 this.upstream = d;
59
60 downstream.onSubscribe(this);
61 }
62 }
63
64 @Override
65 public void onSuccess(T value) {
66 upstream = DisposableHelper.DISPOSED;
67 downstream.onComplete();
68 }
69
70 @Override
71 public void onError(Throwable e) {
72 upstream = DisposableHelper.DISPOSED;
73 downstream.onError(e);
74 }
75
76 @Override
77 public void onComplete() {
78 upstream = DisposableHelper.DISPOSED;
79 downstream.onComplete();
80 }
81
82 @Override
83 public boolean isDisposed() {
84 return upstream.isDisposed();
85 }
86
87 @Override
88 public void dispose() {
89 upstream.dispose();
90 upstream = DisposableHelper.DISPOSED;
91 }
92
93 }
94
95 }