Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Completable.andThen(Completable), deprecate endWith() #3948

Merged
merged 3 commits into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/main/java/rx/Completable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,19 @@ public final <T> Single<T> andThen(Single<T> next) {
requireNonNull(next);
return next.delaySubscription(toObservable());
}

/**
* Returns a completable that first runs this Completable
* and then the other completable.
* <p>
* This is an alias for {@link #concatWith(Completable)}.
* @param next the other Completable, not null
* @return the new Completable instance
* @throws NullPointerException if other is null
*/
public final Completable andThen(Completable next) {
return concatWith(next);
}

/**
* Concatenates this Completable with another Completable.
Expand Down Expand Up @@ -1396,20 +1409,23 @@ public void call(Throwable e) {
* @param other the other Completable, not null
* @return the new Completable instance
* @throws NullPointerException if other is null
* @deprecated Use {@link #andThen(rx.Completable)} instead.
*/
@Deprecated
public final Completable endWith(Completable other) {
return concatWith(other);
return andThen(other);
}

/**
* Returns an Observable that first runs this Completable instance and
* resumes with the given next Observable.
* @param next the next Observable to continue
* @return the new Observable instance
* @throws NullPointerException if next is null
* @deprecated Use {@link #andThen(rx.Observable)} instead.
*/
@Deprecated
public final <T> Observable<T> endWith(Observable<T> next) {
return next.startWith(this.<T>toObservable());
return andThen(next);
}

/**
Expand Down
24 changes: 12 additions & 12 deletions src/test/java/rx/CompletableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3530,20 +3530,20 @@ public void startWithFlowableNull() {
}

@Test(expected = NullPointerException.class)
public void endWithCompletableNull() {
normal.completable.endWith((Completable)null);
public void andThenCompletableNull() {
normal.completable.andThen((Completable)null);
}

@Test(expected = NullPointerException.class)
public void endWithFlowableNull() {
normal.completable.endWith((Observable<Object>)null);
public void andThenFlowableNull() {
normal.completable.andThen((Observable<Object>)null);
}

@Test(timeout = 1000)
public void endWithCompletableNormal() {
public void andThenCompletableNormal() {
final AtomicBoolean run = new AtomicBoolean();
Completable c = normal.completable
.endWith(Completable.fromCallable(new Callable<Object>() {
.andThen(Completable.fromCallable(new Callable<Object>() {
@Override
public Object call() throws Exception {
run.set(normal.get() == 0);
Expand All @@ -3558,8 +3558,8 @@ public Object call() throws Exception {
}

@Test(timeout = 1000)
public void endWithCompletableError() {
Completable c = normal.completable.endWith(error.completable);
public void andThenCompletableError() {
Completable c = normal.completable.andThen(error.completable);

try {
c.await();
Expand All @@ -3571,10 +3571,10 @@ public void endWithCompletableError() {
}

@Test(timeout = 1000)
public void endWithFlowableNormal() {
public void andThenFlowableNormal() {
final AtomicBoolean run = new AtomicBoolean();
Observable<Object> c = normal.completable
.endWith(Observable.fromCallable(new Callable<Object>() {
.andThen(Observable.fromCallable(new Callable<Object>() {
@Override
public Object call() throws Exception {
run.set(normal.get() == 0);
Expand All @@ -3595,9 +3595,9 @@ public Object call() throws Exception {
}

@Test(timeout = 1000)
public void endWithFlowableError() {
public void andThenFlowableError() {
Observable<Object> c = normal.completable
.endWith(Observable.error(new TestException()));
.andThen(Observable.error(new TestException()));

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

Expand Down