| 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.Predicate; |
| 20 |
|
| 21 |
public final class CompletableOnErrorComplete extends Completable { |
| 22 |
|
| 23 |
final CompletableSource source; |
| 24 |
|
| 25 |
final Predicate<? super Throwable> predicate; |
| 26 |
|
| 27 |
public CompletableOnErrorComplete(CompletableSource source, Predicate<? super Throwable> predicate) { |
| 28 |
this.source = source; |
| 29 |
this.predicate = predicate; |
| 30 |
} |
| 31 |
|
| 32 |
@Override |
| 33 |
protected void subscribeActual(final CompletableObserver observer) { |
| 34 |
|
| 35 |
source.subscribe(new OnError(observer)); |
| 36 |
} |
| 37 |
|
| 38 |
final class OnError implements CompletableObserver { |
| 39 |
|
| 40 |
private final CompletableObserver downstream; |
| 41 |
|
| 42 |
OnError(CompletableObserver observer) { |
| 43 |
this.downstream = observer; |
| 44 |
} |
| 45 |
|
| 46 |
@Override |
| 47 |
public void onComplete() { |
| 48 |
downstream.onComplete(); |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public void onError(Throwable e) { |
| 53 |
boolean b; |
| 54 |
|
| 55 |
try { |
| 56 |
b = predicate.test(e); |
| 57 |
} catch (Throwable ex) { |
| 58 |
Exceptions.throwIfFatal(ex); |
| 59 |
downstream.onError(new CompositeException(e, ex)); |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
if (b) { |
| 64 |
downstream.onComplete(); |
| 65 |
} else { |
| 66 |
downstream.onError(e); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public void onSubscribe(Disposable d) { |
| 72 |
downstream.onSubscribe(d); |
| 73 |
} |
| 74 |
|
| 75 |
} |
| 76 |
} |