Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/observers/DisposableAutoReleaseMultiObserver.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 /*
15 * Copyright 2016-2019 David Karnok
16 *
17 * Licensed under the Apache License, Version 2.0 (the "License");
18 * you may not use this file except in compliance with the License.
19 * You may obtain a copy of the License at
20 *
21 * http://www.apache.org/licenses/LICENSE-2.0
22 *
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an "AS IS" BASIS,
25 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 * See the License for the specific language governing permissions and
27 * limitations under the License.
28 */
29
30 package io.reactivex.rxjava3.internal.observers;
31
32 import io.reactivex.rxjava3.core.*;
33 import io.reactivex.rxjava3.disposables.DisposableContainer;
34 import io.reactivex.rxjava3.exceptions.Exceptions;
35 import io.reactivex.rxjava3.functions.*;
36 import io.reactivex.rxjava3.internal.disposables.DisposableHelper;
37 import io.reactivex.rxjava3.plugins.RxJavaPlugins;
38
39 /**
40 * Wraps lambda callbacks and when the upstream terminates or this (Single | Maybe | Completable)
41 * observer gets disposed, removes itself from a {@link io.reactivex.rxjava3.disposables.CompositeDisposable}.
42 * <p>History: 0.18.0 @ RxJavaExtensions
43 * @param <T> the element type consumed
44 * @since 3.1.0
45 */
46 public final class DisposableAutoReleaseMultiObserver<T>
47 extends AbstractDisposableAutoRelease
48 implements SingleObserver<T>, MaybeObserver<T>, CompletableObserver {
49
50 private static final long serialVersionUID = 8924480688481408726L;
51
52 final Consumer<? super T> onSuccess;
53
54 public DisposableAutoReleaseMultiObserver(
55 DisposableContainer composite,
56 Consumer<? super T> onSuccess,
57 Consumer<? super Throwable> onError,
58 Action onComplete
59 ) {
60 super(composite, onError, onComplete);
61 this.onSuccess = onSuccess;
62 }
63
64 @Override
65 public void onSuccess(T t) {
66 if (get() != DisposableHelper.DISPOSED) {
67 lazySet(DisposableHelper.DISPOSED);
68 try {
69 onSuccess.accept(t);
70 } catch (Throwable e) {
71 Exceptions.throwIfFatal(e);
72 RxJavaPlugins.onError(e);
73 }
74 }
75 removeSelf();
76 }
77
78 }