Skip to content

Commit 6f1cb00

Browse files
JakeWhartonakarnokd
authored andcommitted
Merge CancelledSubscriber into EmptySubscriber. (#4083)
1 parent 3fd1cc8 commit 6f1cb00

File tree

4 files changed

+16
-62
lines changed

4 files changed

+16
-62
lines changed

src/main/java/io/reactivex/internal/subscribers/flowable/CancelledSubscriber.java

-51
This file was deleted.

src/main/java/io/reactivex/internal/subscribers/flowable/EmptySubscriber.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,29 @@
1818
import io.reactivex.plugins.RxJavaPlugins;
1919

2020
/**
21-
* A subscriber that ignores all events (onError is forwarded to RxJavaPlugins though).
21+
* A subscriber that ignores all events.
2222
*/
2323
public enum EmptySubscriber implements Subscriber<Object> {
2424
/** Empty instance that reports error to the plugins. */
25-
INSTANCE(true),
25+
INSTANCE(true, false),
2626
/** Empty instance that doesn't report to the plugins to avoid flooding the test output. */
27-
INSTANCE_NOERROR(false);
27+
INSTANCE_NOERROR(false, false),
28+
/** Empty instance that cancels subscriptions. */
29+
CANCELLED(true, true);
2830

29-
final boolean reportError;
31+
private final boolean reportError;
32+
private final boolean cancelSubscription;
3033

31-
EmptySubscriber(boolean reportError) {
34+
EmptySubscriber(boolean reportError, boolean cancelSubscription) {
3235
this.reportError = reportError;
36+
this.cancelSubscription = cancelSubscription;
3337
}
3438

3539
@Override
3640
public void onSubscribe(Subscription s) {
37-
41+
if (cancelSubscription) {
42+
s.cancel();
43+
}
3844
}
3945

4046
@Override

src/main/java/io/reactivex/subscribers/Subscribers.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static <T> Subscriber<T> empty() {
3737

3838
@SuppressWarnings("unchecked")
3939
public static <T> Subscriber<T> cancelled() {
40-
return (Subscriber<T>)CancelledSubscriber.INSTANCE;
40+
return (Subscriber<T>)EmptySubscriber.CANCELLED;
4141
}
4242

4343
public static <T> DisposableSubscriber<T> emptyDisposable() {

src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929
import io.reactivex.disposables.Disposable;
3030
import io.reactivex.flowable.TestHelper;
3131
import io.reactivex.functions.*;
32-
import io.reactivex.internal.subscribers.flowable.CancelledSubscriber;
3332
import io.reactivex.processors.ReplayProcessor;
3433
import io.reactivex.schedulers.*;
35-
import io.reactivex.subscribers.TestSubscriber;
34+
import io.reactivex.subscribers.*;
3635

3736
public class FlowableRefCountTest {
3837

@@ -441,7 +440,7 @@ public void accept(Long t1) {
441440

442441
@Test
443442
public void testAlreadyUnsubscribedClient() {
444-
Subscriber<Integer> done = CancelledSubscriber.instance();
443+
Subscriber<Integer> done = Subscribers.cancelled();
445444

446445
Subscriber<Integer> o = TestHelper.mockSubscriber();
447446

@@ -460,7 +459,7 @@ public void testAlreadyUnsubscribedClient() {
460459
public void testAlreadyUnsubscribedInterleavesWithClient() {
461460
ReplayProcessor<Integer> source = ReplayProcessor.create();
462461

463-
Subscriber<Integer> done = CancelledSubscriber.instance();
462+
Subscriber<Integer> done = Subscribers.cancelled();
464463

465464
Subscriber<Integer> o = TestHelper.mockSubscriber();
466465
InOrder inOrder = inOrder(o);

0 commit comments

Comments
 (0)