Skip to content

Commit c296d52

Browse files
vanniktechzsxwing
authored andcommitted
Add Completable.andThen(Completable), deprecate endWith() (#3948)
Closes #3947
1 parent 7fed2ed commit c296d52

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

src/main/java/rx/Completable.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,19 @@ public final <T> Single<T> andThen(Single<T> next) {
11321132
requireNonNull(next);
11331133
return next.delaySubscription(toObservable());
11341134
}
1135+
1136+
/**
1137+
* Returns a completable that first runs this Completable
1138+
* and then the other completable.
1139+
* <p>
1140+
* This is an alias for {@link #concatWith(Completable)}.
1141+
* @param next the other Completable, not null
1142+
* @return the new Completable instance
1143+
* @throws NullPointerException if other is null
1144+
*/
1145+
public final Completable andThen(Completable next) {
1146+
return concatWith(next);
1147+
}
11351148

11361149
/**
11371150
* Concatenates this Completable with another Completable.
@@ -1396,20 +1409,23 @@ public void call(Throwable e) {
13961409
* @param other the other Completable, not null
13971410
* @return the new Completable instance
13981411
* @throws NullPointerException if other is null
1412+
* @deprecated Use {@link #andThen(rx.Completable)} instead.
13991413
*/
1414+
@Deprecated
14001415
public final Completable endWith(Completable other) {
1401-
return concatWith(other);
1416+
return andThen(other);
14021417
}
14031418

14041419
/**
14051420
* Returns an Observable that first runs this Completable instance and
14061421
* resumes with the given next Observable.
14071422
* @param next the next Observable to continue
14081423
* @return the new Observable instance
1409-
* @throws NullPointerException if next is null
1424+
* @deprecated Use {@link #andThen(rx.Observable)} instead.
14101425
*/
1426+
@Deprecated
14111427
public final <T> Observable<T> endWith(Observable<T> next) {
1412-
return next.startWith(this.<T>toObservable());
1428+
return andThen(next);
14131429
}
14141430

14151431
/**

src/test/java/rx/CompletableTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3530,20 +3530,20 @@ public void startWithFlowableNull() {
35303530
}
35313531

35323532
@Test(expected = NullPointerException.class)
3533-
public void endWithCompletableNull() {
3534-
normal.completable.endWith((Completable)null);
3533+
public void andThenCompletableNull() {
3534+
normal.completable.andThen((Completable)null);
35353535
}
35363536

35373537
@Test(expected = NullPointerException.class)
3538-
public void endWithFlowableNull() {
3539-
normal.completable.endWith((Observable<Object>)null);
3538+
public void andThenFlowableNull() {
3539+
normal.completable.andThen((Observable<Object>)null);
35403540
}
35413541

35423542
@Test(timeout = 1000)
3543-
public void endWithCompletableNormal() {
3543+
public void andThenCompletableNormal() {
35443544
final AtomicBoolean run = new AtomicBoolean();
35453545
Completable c = normal.completable
3546-
.endWith(Completable.fromCallable(new Callable<Object>() {
3546+
.andThen(Completable.fromCallable(new Callable<Object>() {
35473547
@Override
35483548
public Object call() throws Exception {
35493549
run.set(normal.get() == 0);
@@ -3558,8 +3558,8 @@ public Object call() throws Exception {
35583558
}
35593559

35603560
@Test(timeout = 1000)
3561-
public void endWithCompletableError() {
3562-
Completable c = normal.completable.endWith(error.completable);
3561+
public void andThenCompletableError() {
3562+
Completable c = normal.completable.andThen(error.completable);
35633563

35643564
try {
35653565
c.await();
@@ -3571,10 +3571,10 @@ public void endWithCompletableError() {
35713571
}
35723572

35733573
@Test(timeout = 1000)
3574-
public void endWithFlowableNormal() {
3574+
public void andThenFlowableNormal() {
35753575
final AtomicBoolean run = new AtomicBoolean();
35763576
Observable<Object> c = normal.completable
3577-
.endWith(Observable.fromCallable(new Callable<Object>() {
3577+
.andThen(Observable.fromCallable(new Callable<Object>() {
35783578
@Override
35793579
public Object call() throws Exception {
35803580
run.set(normal.get() == 0);
@@ -3595,9 +3595,9 @@ public Object call() throws Exception {
35953595
}
35963596

35973597
@Test(timeout = 1000)
3598-
public void endWithFlowableError() {
3598+
public void andThenFlowableError() {
35993599
Observable<Object> c = normal.completable
3600-
.endWith(Observable.error(new TestException()));
3600+
.andThen(Observable.error(new TestException()));
36013601

36023602
TestSubscriber<Object> ts = new TestSubscriber<Object>();
36033603

0 commit comments

Comments
 (0)