| 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.observers; |
| 15 |
|
| 16 |
import java.util.concurrent.atomic.AtomicReference; |
| 17 |
|
| 18 |
import io.reactivex.rxjava3.core.SingleObserver; |
| 19 |
import io.reactivex.rxjava3.disposables.Disposable; |
| 20 |
import io.reactivex.rxjava3.exceptions.*; |
| 21 |
import io.reactivex.rxjava3.functions.BiConsumer; |
| 22 |
import io.reactivex.rxjava3.internal.disposables.DisposableHelper; |
| 23 |
import io.reactivex.rxjava3.plugins.RxJavaPlugins; |
| 24 |
|
| 25 |
public final class BiConsumerSingleObserver<T> |
| 26 |
extends AtomicReference<Disposable> |
| 27 |
implements SingleObserver<T>, Disposable { |
| 28 |
|
| 29 |
private static final long serialVersionUID = 4943102778943297569L; |
| 30 |
final BiConsumer<? super T, ? super Throwable> onCallback; |
| 31 |
|
| 32 |
public BiConsumerSingleObserver(BiConsumer<? super T, ? super Throwable> onCallback) { |
| 33 |
this.onCallback = onCallback; |
| 34 |
} |
| 35 |
|
| 36 |
@Override |
| 37 |
public void onError(Throwable e) { |
| 38 |
try { |
| 39 |
lazySet(DisposableHelper.DISPOSED); |
| 40 |
onCallback.accept(null, e); |
| 41 |
} catch (Throwable ex) { |
| 42 |
Exceptions.throwIfFatal(ex); |
| 43 |
RxJavaPlugins.onError(new CompositeException(e, ex)); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
@Override |
| 48 |
public void onSubscribe(Disposable d) { |
| 49 |
DisposableHelper.setOnce(this, d); |
| 50 |
} |
| 51 |
|
| 52 |
@Override |
| 53 |
public void onSuccess(T value) { |
| 54 |
try { |
| 55 |
lazySet(DisposableHelper.DISPOSED); |
| 56 |
onCallback.accept(value, null); |
| 57 |
} catch (Throwable ex) { |
| 58 |
Exceptions.throwIfFatal(ex); |
| 59 |
RxJavaPlugins.onError(ex); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
@Override |
| 64 |
public void dispose() { |
| 65 |
DisposableHelper.dispose(this); |
| 66 |
} |
| 67 |
|
| 68 |
@Override |
| 69 |
public boolean isDisposed() { |
| 70 |
return get() == DisposableHelper.DISPOSED; |
| 71 |
} |
| 72 |
} |