Skip to content

Commit 2cdf1c0

Browse files
authored
1.x: Completable.doAfterTerminate to run after onError as well (#4830)
1 parent bebdec6 commit 2cdf1c0

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/main/java/rx/Completable.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,20 +1347,20 @@ public final Completable doOnError(Action1<? super Throwable> onError) {
13471347
* @param onSubscribe the consumer called when a CompletableSubscriber subscribes.
13481348
* @param onError the consumer called when this emits an onError event
13491349
* @param onComplete the runnable called just before when this Completable completes normally
1350-
* @param onAfterComplete the runnable called after this Completable completes normally
1350+
* @param onAfterTerminate the runnable called after this Completable terminates
13511351
* @param onUnsubscribe the runnable called when the child cancels the subscription
13521352
* @return the new Completable instance
13531353
*/
13541354
protected final Completable doOnLifecycle(
13551355
final Action1<? super Subscription> onSubscribe,
13561356
final Action1<? super Throwable> onError,
13571357
final Action0 onComplete,
1358-
final Action0 onAfterComplete,
1358+
final Action0 onAfterTerminate,
13591359
final Action0 onUnsubscribe) {
13601360
requireNonNull(onSubscribe);
13611361
requireNonNull(onError);
13621362
requireNonNull(onComplete);
1363-
requireNonNull(onAfterComplete);
1363+
requireNonNull(onAfterTerminate);
13641364
requireNonNull(onUnsubscribe);
13651365
return create(new OnSubscribe() {
13661366
@Override
@@ -1379,7 +1379,7 @@ public void onCompleted() {
13791379
s.onCompleted();
13801380

13811381
try {
1382-
onAfterComplete.call();
1382+
onAfterTerminate.call();
13831383
} catch (Throwable e) {
13841384
RxJavaHooks.onError(e);
13851385
}
@@ -1394,6 +1394,12 @@ public void onError(Throwable e) {
13941394
}
13951395

13961396
s.onError(e);
1397+
1398+
try {
1399+
onAfterTerminate.call();
1400+
} catch (Throwable ex) {
1401+
RxJavaHooks.onError(ex);
1402+
}
13971403
}
13981404

13991405
@Override
@@ -1455,12 +1461,12 @@ public void call(Throwable e) {
14551461
/**
14561462
* Returns a Completable instance that calls the given onAfterComplete callback after this
14571463
* Completable completes normally.
1458-
* @param onAfterComplete the callback to call after this Completable emits an onComplete event.
1464+
* @param onAfterTerminate the callback to call after this Completable emits an onCompleted or onError event.
14591465
* @return the new Completable instance
14601466
* @throws NullPointerException if onAfterComplete is null
14611467
*/
1462-
public final Completable doAfterTerminate(Action0 onAfterComplete) {
1463-
return doOnLifecycle(Actions.empty(), Actions.empty(), Actions.empty(), onAfterComplete, Actions.empty());
1468+
public final Completable doAfterTerminate(Action0 onAfterTerminate) {
1469+
return doOnLifecycle(Actions.empty(), Actions.empty(), Actions.empty(), onAfterTerminate, Actions.empty());
14641470
}
14651471

14661472
/**

src/test/java/rx/CompletableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ public void call() {
20582058
// expected
20592059
}
20602060

2061-
Assert.assertFalse("Closure called", doneAfter.get());
2061+
Assert.assertTrue("Closure called", doneAfter.get());
20622062
}
20632063

20642064
@Test(expected = NullPointerException.class)

0 commit comments

Comments
 (0)