Skip to content

Commit 88fafd8

Browse files
Mauinakarnokd
authored andcommitted
rename Observable and Single #doOnCancel to #doOnDispose (#4458)
* rename Observable/Single #doOnCancel to #doOnDispose * align naming of Completable onDispose arguments * aligns javadoc
1 parent 52dc050 commit 88fafd8

19 files changed

+70
-70
lines changed

src/main/java/io/reactivex/Completable.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ public final Completable doOnComplete(Action onComplete) {
956956
* <dt><b>Scheduler:</b></dt>
957957
* <dd>{@code doOnDispose} does not operate by default on a particular {@link Scheduler}.</dd>
958958
* </dl>
959-
* @param onDispose the callback to call when the child subscriber cancels the subscription
959+
* @param onDispose the callback to call when the child subscriber disposes the subscription
960960
* @return the new Completable instance
961961
* @throws NullPointerException if onDispose is null
962962
*/
@@ -995,7 +995,7 @@ public final Completable doOnError(Consumer<? super Throwable> onError) {
995995
* @param onError the consumer called when this emits an onError event
996996
* @param onComplete the runnable called just before when this Completable completes normally
997997
* @param onAfterTerminate the runnable called after this Completable completes normally
998-
* @param onDisposed the runnable called when the child cancels the subscription
998+
* @param onDispose the runnable called when the child disposes the subscription
999999
* @return the new Completable instance
10001000
*/
10011001
@SchedulerSupport(SchedulerSupport.NONE)
@@ -1005,14 +1005,14 @@ private Completable doOnLifecycle(
10051005
final Action onComplete,
10061006
final Action onTerminate,
10071007
final Action onAfterTerminate,
1008-
final Action onDisposed) {
1008+
final Action onDispose) {
10091009
ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null");
10101010
ObjectHelper.requireNonNull(onError, "onError is null");
10111011
ObjectHelper.requireNonNull(onComplete, "onComplete is null");
10121012
ObjectHelper.requireNonNull(onTerminate, "onTerminate is null");
10131013
ObjectHelper.requireNonNull(onAfterTerminate, "onAfterTerminate is null");
1014-
ObjectHelper.requireNonNull(onDisposed, "onDisposed is null");
1015-
return RxJavaPlugins.onAssembly(new CompletablePeek(this, onSubscribe, onError, onComplete, onTerminate, onAfterTerminate, onDisposed));
1014+
ObjectHelper.requireNonNull(onDispose, "onDispose is null");
1015+
return RxJavaPlugins.onAssembly(new CompletablePeek(this, onSubscribe, onError, onComplete, onTerminate, onAfterTerminate, onDispose));
10161016
}
10171017

10181018
/**

src/main/java/io/reactivex/Observable.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6294,17 +6294,17 @@ public final Observable<T> doAfterTerminate(Action onFinally) {
62946294
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/doOnUnsubscribe.png" alt="">
62956295
* <dl>
62966296
* <dt><b>Scheduler:</b></dt>
6297-
* <dd>{@code doOnUnsubscribe} does not operate by default on a particular {@link Scheduler}.</dd>
6297+
* <dd>{@code doOnDispose} does not operate by default on a particular {@link Scheduler}.</dd>
62986298
* </dl>
62996299
*
6300-
* @param onCancel
6301-
* the action that gets called when the source {@code ObservableSource}'s Subscription is cancelled
6300+
* @param onDispose
6301+
* the action that gets called when the source {@code ObservableSource}'s Subscription is disposed
63026302
* @return the source {@code ObservableSource} modified so as to call this Action when appropriate
63036303
* @see <a href="http://reactivex.io/documentation/operators/do.html">ReactiveX operators documentation: Do</a>
63046304
*/
63056305
@SchedulerSupport(SchedulerSupport.NONE)
6306-
public final Observable<T> doOnCancel(Action onCancel) {
6307-
return doOnLifecycle(Functions.emptyConsumer(), onCancel);
6306+
public final Observable<T> doOnDispose(Action onDispose) {
6307+
return doOnLifecycle(Functions.emptyConsumer(), onDispose);
63086308
}
63096309

63106310
/**
@@ -6437,16 +6437,16 @@ public final Observable<T> doOnError(Consumer<? super Throwable> onError) {
64376437
*
64386438
* @param onSubscribe
64396439
* a Consumer called with the Subscription sent via Subscriber.onSubscribe()
6440-
* @param onCancel
6441-
* called when the downstream cancels the Subscription via cancel()
6440+
* @param onDispose
6441+
* called when the downstream disposes the Subscription via dispose()
64426442
* @return the source ObservableSource with the side-effecting behavior applied
64436443
* @see <a href="http://reactivex.io/documentation/operators/do.html">ReactiveX operators documentation: Do</a>
64446444
*/
64456445
@SchedulerSupport(SchedulerSupport.NONE)
6446-
public final Observable<T> doOnLifecycle(final Consumer<? super Disposable> onSubscribe, final Action onCancel) {
6446+
public final Observable<T> doOnLifecycle(final Consumer<? super Disposable> onSubscribe, final Action onDispose) {
64476447
ObjectHelper.requireNonNull(onSubscribe, "onSubscribe is null");
6448-
ObjectHelper.requireNonNull(onCancel, "onCancel is null");
6449-
return RxJavaPlugins.onAssembly(new ObservableDoOnLifecycle<T>(this, onSubscribe, onCancel));
6448+
ObjectHelper.requireNonNull(onDispose, "onDispose is null");
6449+
return RxJavaPlugins.onAssembly(new ObservableDoOnLifecycle<T>(this, onSubscribe, onDispose));
64506450
}
64516451

64526452
/**

src/main/java/io/reactivex/Single.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,13 +1579,13 @@ public final Single<T> doOnError(final Consumer<? super Throwable> onError) {
15791579
* <dt><b>Scheduler:</b></dt>
15801580
* <dd>{@code doOnSubscribe} does not operate by default on a particular {@link Scheduler}.</dd>
15811581
* </dl>
1582-
* @param onCancel the runnable called when the subscription is cancelled (disposed)
1582+
* @param onDispose the runnable called when the subscription is disposed
15831583
* @return the new Single instance
15841584
* @since 2.0
15851585
*/
1586-
public final Single<T> doOnCancel(final Action onCancel) {
1587-
ObjectHelper.requireNonNull(onCancel, "onCancel is null");
1588-
return RxJavaPlugins.onAssembly(new SingleDoOnCancel<T>(this, onCancel));
1586+
public final Single<T> doOnDispose(final Action onDispose) {
1587+
ObjectHelper.requireNonNull(onDispose, "onDispose is null");
1588+
return RxJavaPlugins.onAssembly(new SingleDoOnDispose<T>(this, onDispose));
15891589
}
15901590

15911591
/**

src/main/java/io/reactivex/internal/operators/completable/CompletablePeek.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ public final class CompletablePeek extends Completable {
2828
final Action onComplete;
2929
final Action onTerminate;
3030
final Action onAfterTerminate;
31-
final Action onDisposed;
31+
final Action onDispose;
3232

3333
public CompletablePeek(CompletableSource source, Consumer<? super Disposable> onSubscribe,
3434
Consumer<? super Throwable> onError,
3535
Action onComplete,
3636
Action onTerminate,
3737
Action onAfterTerminate,
38-
Action onDisposed) {
38+
Action onDispose) {
3939
this.source = source;
4040
this.onSubscribe = onSubscribe;
4141
this.onError = onError;
4242
this.onComplete = onComplete;
4343
this.onTerminate = onTerminate;
4444
this.onAfterTerminate = onAfterTerminate;
45-
this.onDisposed = onDisposed;
45+
this.onDispose = onDispose;
4646
}
4747

4848
@Override
@@ -107,7 +107,7 @@ public void onSubscribe(final Disposable d) {
107107
@Override
108108
public void run() {
109109
try {
110-
onDisposed.run();
110+
onDispose.run();
111111
} catch (Throwable e) {
112112
Exceptions.throwIfFatal(e);
113113
RxJavaPlugins.onError(e);

src/main/java/io/reactivex/internal/operators/observable/ObservableDoOnLifecycle.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919

2020
public final class ObservableDoOnLifecycle<T> extends AbstractObservableWithUpstream<T, T> {
2121
private final Consumer<? super Disposable> onSubscribe;
22-
private final Action onCancel;
22+
private final Action onDispose;
2323

2424
public ObservableDoOnLifecycle(Observable<T> upstream, Consumer<? super Disposable> onSubscribe,
25-
Action onCancel) {
25+
Action onDispose) {
2626
super(upstream);
2727
this.onSubscribe = onSubscribe;
28-
this.onCancel = onCancel;
28+
this.onDispose = onDispose;
2929
}
3030

3131
@Override
3232
protected void subscribeActual(Observer<? super T> observer) {
33-
source.subscribe(new SubscriptionLambdaObserver<T>(observer, onSubscribe, onCancel));
33+
source.subscribe(new SubscriptionLambdaObserver<T>(observer, onSubscribe, onDispose));
3434
}
3535
}

src/main/java/io/reactivex/internal/operators/single/SingleDoOnCancel.java renamed to src/main/java/io/reactivex/internal/operators/single/SingleDoOnDispose.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,38 @@
2020
import io.reactivex.internal.disposables.DisposableHelper;
2121
import io.reactivex.plugins.RxJavaPlugins;
2222

23-
public final class SingleDoOnCancel<T> extends Single<T> {
23+
public final class SingleDoOnDispose<T> extends Single<T> {
2424
final SingleSource<T> source;
2525

26-
final Action onCancel;
26+
final Action onDispose;
2727

28-
public SingleDoOnCancel(SingleSource<T> source, Action onCancel) {
28+
public SingleDoOnDispose(SingleSource<T> source, Action onDispose) {
2929
this.source = source;
30-
this.onCancel = onCancel;
30+
this.onDispose = onDispose;
3131
}
3232

3333
@Override
3434
protected void subscribeActual(final SingleObserver<? super T> s) {
3535

36-
source.subscribe(new DoOnCancelObserver<T>(s, onCancel));
36+
source.subscribe(new DoOnDisposeObserver<T>(s, onDispose));
3737
}
3838

39-
static final class DoOnCancelObserver<T> implements SingleObserver<T>, Disposable {
39+
static final class DoOnDisposeObserver<T> implements SingleObserver<T>, Disposable {
4040
final SingleObserver<? super T> actual;
4141

42-
final Action onCancel;
42+
final Action onDispose;
4343

4444
Disposable d;
4545

46-
public DoOnCancelObserver(SingleObserver<? super T> actual, Action onCancel) {
46+
public DoOnDisposeObserver(SingleObserver<? super T> actual, Action onDispose) {
4747
this.actual = actual;
48-
this.onCancel = onCancel;
48+
this.onDispose = onDispose;
4949
}
5050

5151
@Override
5252
public void dispose() {
5353
try {
54-
onCancel.run();
54+
onDispose.run();
5555
} catch (Throwable ex) {
5656
Exceptions.throwIfFatal(ex);
5757
RxJavaPlugins.onError(ex);

src/main/java/io/reactivex/internal/subscribers/observable/SubscriptionLambdaObserver.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
public final class SubscriptionLambdaObserver<T> implements Observer<T>, Disposable {
2424
final Observer<? super T> actual;
2525
final Consumer<? super Disposable> onSubscribe;
26-
final Action onCancel;
26+
final Action onDispose;
2727

2828
Disposable s;
2929

3030
public SubscriptionLambdaObserver(Observer<? super T> actual,
3131
Consumer<? super Disposable> onSubscribe,
32-
Action onCancel) {
32+
Action onDispose) {
3333
this.actual = actual;
3434
this.onSubscribe = onSubscribe;
35-
this.onCancel = onCancel;
35+
this.onDispose = onDispose;
3636
}
3737

3838
@Override
@@ -73,7 +73,7 @@ public void onComplete() {
7373
@Override
7474
public void dispose() {
7575
try {
76-
onCancel.run();
76+
onDispose.run();
7777
} catch (Throwable e) {
7878
Exceptions.throwIfFatal(e);
7979
RxJavaPlugins.onError(e);

src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void accept(String v) {
108108
@Test
109109
public void testUnsubscribeSource() throws Exception {
110110
Action unsubscribe = mock(Action.class);
111-
Observable<Integer> o = Observable.just(1).doOnCancel(unsubscribe).cache();
111+
Observable<Integer> o = Observable.just(1).doOnDispose(unsubscribe).cache();
112112
o.subscribe();
113113
o.subscribe();
114114
o.subscribe();

src/test/java/io/reactivex/internal/operators/observable/ObservableDelayTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void testDelaySubscription() {
212212
}
213213

214214
@Test
215-
public void testDelaySubscriptionCancelBeforeTime() {
215+
public void testDelaySubscriptionDisposeBeforeTime() {
216216
Observable<Integer> result = Observable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler);
217217

218218
Observer<Object> o = TestHelper.mockObserver();

src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnUnsubscribeTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void testDoOnUnsubscribe() throws Exception {
4141
// The stream needs to be infinite to ensure the stream does not terminate
4242
// before it is unsubscribed
4343
.interval(50, TimeUnit.MILLISECONDS)
44-
.doOnCancel(new Action() {
44+
.doOnDispose(new Action() {
4545
@Override
4646
public void run() {
4747
// Test that upper stream will be notified for un-subscription
@@ -57,7 +57,7 @@ public void accept(Long aLong) {
5757
onNextLatch.countDown();
5858
}
5959
})
60-
.doOnCancel(new Action() {
60+
.doOnDispose(new Action() {
6161
@Override
6262
public void run() {
6363
// Test that lower stream will be notified for a direct un-subscription
@@ -103,7 +103,7 @@ public void testDoOnUnSubscribeWorksWithRefCount() throws Exception {
103103
// The stream needs to be infinite to ensure the stream does not terminate
104104
// before it is unsubscribed
105105
.interval(50, TimeUnit.MILLISECONDS)
106-
.doOnCancel(new Action() {
106+
.doOnDispose(new Action() {
107107
@Override
108108
public void run() {
109109
// Test that upper stream will be notified for un-subscription
@@ -118,7 +118,7 @@ public void accept(Long aLong) {
118118
onNextLatch.countDown();
119119
}
120120
})
121-
.doOnCancel(new Action() {
121+
.doOnDispose(new Action() {
122122
@Override
123123
public void run() {
124124
// Test that lower stream will be notified for un-subscription

src/test/java/io/reactivex/internal/operators/observable/ObservableIgnoreElementsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void testErrorReceived() {
8080
@Test
8181
public void testUnsubscribesFromUpstream() {
8282
final AtomicBoolean unsub = new AtomicBoolean();
83-
Observable.range(1, 10).doOnCancel(new Action() {
83+
Observable.range(1, 10).doOnDispose(new Action() {
8484
@Override
8585
public void run() {
8686
unsub.set(true);

src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public void accept(Integer t1) {
192192
sourceEmission.incrementAndGet();
193193
}
194194
})
195-
.doOnCancel(new Action() {
195+
.doOnDispose(new Action() {
196196
@Override
197197
public void run() {
198198
sourceUnsubscribed.set(true);
@@ -209,7 +209,7 @@ public void run() {
209209
@Override
210210
public void onNext(Integer t) {
211211
if (valueCount() == 2) {
212-
source.doOnCancel(new Action() {
212+
source.doOnDispose(new Action() {
213213
@Override
214214
public void run() {
215215
child2Unsubscribed.set(true);
@@ -220,7 +220,7 @@ public void run() {
220220
}
221221
};
222222

223-
source.doOnCancel(new Action() {
223+
source.doOnDispose(new Action() {
224224
@Override
225225
public void run() {
226226
child1Unsubscribed.set(true);

src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void accept(Disposable s) {
170170
subscribeCount.incrementAndGet();
171171
}
172172
})
173-
.doOnCancel(new Action() {
173+
.doOnDispose(new Action() {
174174
@Override
175175
public void run() {
176176
System.out.println("******************************* Unsubscribe received");
@@ -215,7 +215,7 @@ public void accept(Disposable s) {
215215
subscribeLatch.countDown();
216216
}
217217
})
218-
.doOnCancel(new Action() {
218+
.doOnDispose(new Action() {
219219
@Override
220220
public void run() {
221221
System.out.println("******************************* Unsubscribe received");
@@ -253,7 +253,7 @@ public void testConnectUnsubscribeRaceConditionLoop() throws InterruptedExceptio
253253
public void testConnectUnsubscribeRaceCondition() throws InterruptedException {
254254
final AtomicInteger subUnsubCount = new AtomicInteger();
255255
Observable<Long> o = synchronousInterval()
256-
.doOnCancel(new Action() {
256+
.doOnDispose(new Action() {
257257
@Override
258258
public void run() {
259259
System.out.println("******************************* Unsubscribe received");

src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public void testIssue2191_UnsubscribeSource() throws Exception {
522522

523523
ConnectableObservable<Integer> replay = source
524524
.doOnNext(sourceNext)
525-
.doOnCancel(sourceUnsubscribed)
525+
.doOnDispose(sourceUnsubscribed)
526526
.doOnComplete(sourceCompleted)
527527
.replay();
528528

@@ -572,7 +572,7 @@ public void testIssue2191_SchedulerUnsubscribe() throws Exception {
572572
// NbpObservable under test
573573
ConnectableObservable<Integer> replay = Observable.just(1, 2, 3)
574574
.doOnNext(sourceNext)
575-
.doOnCancel(sourceUnsubscribed)
575+
.doOnDispose(sourceUnsubscribed)
576576
.doOnComplete(sourceCompleted)
577577
.subscribeOn(mockScheduler).replay();
578578

@@ -629,7 +629,7 @@ public void testIssue2191_SchedulerUnsubscribeOnError() throws Exception {
629629
when(mockFunc.apply(2)).thenThrow(illegalArgumentException);
630630
ConnectableObservable<Integer> replay = Observable.just(1, 2, 3).map(mockFunc)
631631
.doOnNext(sourceNext)
632-
.doOnCancel(sourceUnsubscribed)
632+
.doOnDispose(sourceUnsubscribed)
633633
.doOnComplete(sourceCompleted)
634634
.doOnError(sourceError)
635635
.subscribeOn(mockScheduler).replay();
@@ -850,7 +850,7 @@ public void accept(String v) {
850850
@Test
851851
public void testUnsubscribeSource() throws Exception {
852852
Action unsubscribe = mock(Action.class);
853-
Observable<Integer> o = Observable.just(1).doOnCancel(unsubscribe).cache();
853+
Observable<Integer> o = Observable.just(1).doOnDispose(unsubscribe).cache();
854854
o.subscribe();
855855
o.subscribe();
856856
o.subscribe();

src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void run() {
6767
unsubscribed.set(true);
6868
}
6969
};
70-
Observable.just(1).doOnCancel(unsubscribeAction)
70+
Observable.just(1).doOnDispose(unsubscribeAction)
7171
.takeLast(1).subscribe();
7272
assertTrue(unsubscribed.get());
7373
}

0 commit comments

Comments
 (0)