Skip to content

Commit 99a46a8

Browse files
author
Aaron Tull
committed
Merge pull request #3566 from artem-zinnatullin/observable-doAfterTerminate
Deprecate Observable.finallyDo() and add Observable.doAfterTerminate() instead
2 parents 150e1e8 + 60769b3 commit 99a46a8

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

src/main/java/rx/Observable.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5115,9 +5115,32 @@ public final Observable<T> filter(Func1<? super T, Boolean> predicate) {
51155115
* {@link Action0}
51165116
* @see <a href="http://reactivex.io/documentation/operators/do.html">ReactiveX operators documentation: Do</a>
51175117
* @see #doOnTerminate(Action0)
5118+
* @deprecated use {@link #doAfterTerminate(Action0)} instead.
51185119
*/
5120+
@Deprecated
51195121
public final Observable<T> finallyDo(Action0 action) {
5120-
return lift(new OperatorFinally<T>(action));
5122+
return lift(new OperatorDoAfterTerminate<T>(action));
5123+
}
5124+
5125+
/**
5126+
* Registers an {@link Action0} to be called when this Observable invokes either
5127+
* {@link Observer#onCompleted onCompleted} or {@link Observer#onError onError}.
5128+
* <p>
5129+
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/finallyDo.png" alt="">
5130+
* <dl>
5131+
* <dt><b>Scheduler:</b></dt>
5132+
* <dd>{@code doAfterTerminate} does not operate by default on a particular {@link Scheduler}.</dd>
5133+
* </dl>
5134+
*
5135+
* @param action
5136+
* an {@link Action0} to be invoked when the source Observable finishes
5137+
* @return an Observable that emits the same items as the source Observable, then invokes the
5138+
* {@link Action0}
5139+
* @see <a href="http://reactivex.io/documentation/operators/do.html">ReactiveX operators documentation: Do</a>
5140+
* @see #doOnTerminate(Action0)
5141+
*/
5142+
public final Observable<T> doAfterTerminate(Action0 action) {
5143+
return lift(new OperatorDoAfterTerminate<T>(action));
51215144
}
51225145

51235146
/**

src/main/java/rx/internal/operators/OperatorFinally.java renamed to src/main/java/rx/internal/operators/OperatorDoAfterTerminate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
*
3030
* @param <T> the value type
3131
*/
32-
public final class OperatorFinally<T> implements Operator<T, T> {
32+
public final class OperatorDoAfterTerminate<T> implements Operator<T, T> {
3333
final Action0 action;
3434

35-
public OperatorFinally(Action0 action) {
35+
public OperatorDoAfterTerminate(Action0 action) {
3636
if (action == null) {
3737
throw new NullPointerException("Action can not be null");
3838
}

src/test/java/rx/internal/operators/OperatorFinallyTest.java renamed to src/test/java/rx/internal/operators/OperatorDoAfterTerminateTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import rx.Observer;
2929
import rx.functions.Action0;
3030

31-
public class OperatorFinallyTest {
31+
public class OperatorDoAfterTerminateTest {
3232

3333
private Action0 aAction0;
3434
private Observer<String> observer;
@@ -42,24 +42,24 @@ public void before() {
4242
}
4343

4444
private void checkActionCalled(Observable<String> input) {
45-
input.finallyDo(aAction0).subscribe(observer);
45+
input.doAfterTerminate(aAction0).subscribe(observer);
4646
verify(aAction0, times(1)).call();
4747
}
4848

4949
@Test
50-
public void testFinallyCalledOnComplete() {
50+
public void testDoAfterTerminateCalledOnComplete() {
5151
checkActionCalled(Observable.from(new String[] { "1", "2", "3" }));
5252
}
5353

5454
@Test
55-
public void testFinallyCalledOnError() {
55+
public void testDoAfterTerminateCalledOnError() {
5656
checkActionCalled(Observable.<String> error(new RuntimeException("expected")));
5757
}
5858

5959
@Test
6060
public void nullActionShouldBeCheckedInConstructor() {
6161
try {
62-
new OperatorFinally<Object>(null);
62+
new OperatorDoAfterTerminate<Object>(null);
6363
fail();
6464
} catch (NullPointerException expected) {
6565
assertEquals("Action can not be null", expected.getMessage());

src/test/java/rx/internal/operators/OperatorObserveOnTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public void call(String t1) {
138138
assertTrue(correctThreadName);
139139
}
140140

141-
}).finallyDo(new Action0() {
141+
}).doAfterTerminate(new Action0() {
142142

143143
@Override
144144
public void call() {

0 commit comments

Comments
 (0)