Skip to content

Commit

Permalink
2.x: Single.subscribe() to report isDisposed() true on success/error (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
akarnokd authored Mar 8, 2017
1 parent 23b46f5 commit 7861679
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public ConsumerSingleObserver(Consumer<? super T> onSuccess, Consumer<? super Th

@Override
public void onError(Throwable e) {
lazySet(DisposableHelper.DISPOSED);
try {
onError.accept(e);
} catch (Throwable ex) {
Expand All @@ -55,6 +56,7 @@ public void onSubscribe(Disposable d) {

@Override
public void onSuccess(T value) {
lazySet(DisposableHelper.DISPOSED);
try {
onSuccess.accept(value);
} catch (Throwable ex) {
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/io/reactivex/single/SingleSubscribeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,14 @@ public void methodTestNoCancel() {

assertTrue(ps.hasObservers());
}

@Test
public void successIsDisposed() {
assertTrue(Single.just(1).subscribe().isDisposed());
}

@Test
public void errorIsDisposed() {
assertTrue(Single.error(new TestException()).subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()).isDisposed());
}
}

0 comments on commit 7861679

Please sign in to comment.