| 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.completable; |
| 15 |
|
| 16 |
import io.reactivex.rxjava3.core.*; |
| 17 |
import io.reactivex.rxjava3.disposables.Disposable; |
| 18 |
import io.reactivex.rxjava3.exceptions.*; |
| 19 |
import io.reactivex.rxjava3.functions.Consumer; |
| 20 |
|
| 21 |
public final class CompletableDoOnEvent extends Completable { |
| 22 |
final CompletableSource source; |
| 23 |
final Consumer<? super Throwable> onEvent; |
| 24 |
|
| 25 |
public CompletableDoOnEvent(final CompletableSource source, final Consumer<? super Throwable> onEvent) { |
| 26 |
this.source = source; |
| 27 |
this.onEvent = onEvent; |
| 28 |
} |
| 29 |
|
| 30 |
@Override |
| 31 |
protected void subscribeActual(final CompletableObserver observer) { |
| 32 |
source.subscribe(new DoOnEvent(observer)); |
| 33 |
} |
| 34 |
|
| 35 |
final class DoOnEvent implements CompletableObserver { |
| 36 |
private final CompletableObserver observer; |
| 37 |
|
| 38 |
DoOnEvent(CompletableObserver observer) { |
| 39 |
this.observer = observer; |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
public void onComplete() { |
| 44 |
try { |
| 45 |
onEvent.accept(null); |
| 46 |
} catch (Throwable e) { |
| 47 |
Exceptions.throwIfFatal(e); |
| 48 |
observer.onError(e); |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
observer.onComplete(); |
| 53 |
} |
| 54 |
|
| 55 |
@Override |
| 56 |
public void onError(Throwable e) { |
| 57 |
try { |
| 58 |
onEvent.accept(e); |
| 59 |
} catch (Throwable ex) { |
| 60 |
Exceptions.throwIfFatal(ex); |
| 61 |
e = new CompositeException(e, ex); |
| 62 |
} |
| 63 |
|
| 64 |
observer.onError(e); |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public void onSubscribe(final Disposable d) { |
| 69 |
observer.onSubscribe(d); |
| 70 |
} |
| 71 |
} |
| 72 |
} |