Skip to content

Commit 7861679

Browse files
authored
2.x: Single.subscribe() to report isDisposed() true on success/error (#5163)
1 parent 23b46f5 commit 7861679

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/main/java/io/reactivex/internal/observers/ConsumerSingleObserver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public ConsumerSingleObserver(Consumer<? super T> onSuccess, Consumer<? super Th
4040

4141
@Override
4242
public void onError(Throwable e) {
43+
lazySet(DisposableHelper.DISPOSED);
4344
try {
4445
onError.accept(e);
4546
} catch (Throwable ex) {
@@ -55,6 +56,7 @@ public void onSubscribe(Disposable d) {
5556

5657
@Override
5758
public void onSuccess(T value) {
59+
lazySet(DisposableHelper.DISPOSED);
5860
try {
5961
onSuccess.accept(value);
6062
} catch (Throwable ex) {

src/test/java/io/reactivex/single/SingleSubscribeTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,14 @@ public void methodTestNoCancel() {
217217

218218
assertTrue(ps.hasObservers());
219219
}
220+
221+
@Test
222+
public void successIsDisposed() {
223+
assertTrue(Single.just(1).subscribe().isDisposed());
224+
}
225+
226+
@Test
227+
public void errorIsDisposed() {
228+
assertTrue(Single.error(new TestException()).subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()).isDisposed());
229+
}
220230
}

0 commit comments

Comments
 (0)