Skip to content

Commit 2cf22f6

Browse files
committed
Call unsubscribe when the terminal events are invoked
1 parent 857986f commit 2cf22f6

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Library to convert between RxJava 1.x and 2.x reactive types.
1717

1818
```
1919
dependencies {
20-
compile "com.github.akarnokd:rxjava2-interop:0.11.3"
20+
compile "com.github.akarnokd:rxjava2-interop:0.11.4"
2121
}
2222
```
2323

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.11.3
1+
version=0.11.4

src/main/java/hu/akarnokd/rxjava/interop/ObservableV1ToFlowableV2.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void onError(Throwable e) {
7171
}
7272
done = true;
7373
actual.onError(e);
74+
unsubscribe(); // v1 expects an unsubscribe call when terminated
7475
}
7576

7677
@Override
@@ -80,6 +81,7 @@ public void onCompleted() {
8081
}
8182
done = true;
8283
actual.onComplete();
84+
unsubscribe(); // v1 expects an unsubscribe call when terminated
8385
}
8486

8587
void requestMore(long n) {

src/main/java/hu/akarnokd/rxjava/interop/ObservableV1ToObservableV2.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public void onError(Throwable e) {
7070
}
7171
done = true;
7272
actual.onError(e);
73+
unsubscribe(); // v1 expects an unsubscribe call when terminated
7374
}
7475

7576
@Override
@@ -79,6 +80,7 @@ public void onCompleted() {
7980
}
8081
done = true;
8182
actual.onComplete();
83+
unsubscribe(); // v1 expects an unsubscribe call when terminated
8284
}
8385

8486
@Override

src/test/java/hu/akarnokd/rxjava/interop/RxJavaInteropTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,4 +1599,53 @@ public void toV1SubscriptionCallsDispose() {
15991599
subscription.unsubscribe();
16001600
verify(disposable).dispose();
16011601
}
1602+
1603+
@Test
1604+
public void v1ObservableIsUnsubscribedOnError() {
1605+
Action0 onUnsubscribe = mock(Action0.class);
1606+
1607+
RxJavaInterop.toV2Observable(rx.Observable.error(new IOException())
1608+
.doOnUnsubscribe(onUnsubscribe))
1609+
.test()
1610+
.assertFailure(IOException.class);
1611+
1612+
verify(onUnsubscribe).call();
1613+
}
1614+
1615+
1616+
@Test
1617+
public void v1ObservableIsUnsubscribedOnCompletion() {
1618+
Action0 onUnsubscribe = mock(Action0.class);
1619+
1620+
RxJavaInterop.toV2Observable(rx.Observable.just(1)
1621+
.doOnUnsubscribe(onUnsubscribe))
1622+
.test()
1623+
.assertResult(1);
1624+
1625+
verify(onUnsubscribe).call();
1626+
}
1627+
1628+
@Test
1629+
public void v1ObservableIsUnsubscribedOnError2() {
1630+
Action0 onUnsubscribe = mock(Action0.class);
1631+
1632+
RxJavaInterop.toV2Flowable(rx.Observable.error(new IOException())
1633+
.doOnUnsubscribe(onUnsubscribe))
1634+
.test()
1635+
.assertFailure(IOException.class);
1636+
1637+
verify(onUnsubscribe).call();
1638+
}
1639+
1640+
@Test
1641+
public void v1ObservableIsUnsubscribedOnCompletion2() {
1642+
Action0 onUnsubscribe = mock(Action0.class);
1643+
1644+
RxJavaInterop.toV2Flowable(rx.Observable.just(1)
1645+
.doOnUnsubscribe(onUnsubscribe))
1646+
.test()
1647+
.assertResult(1);
1648+
1649+
verify(onUnsubscribe).call();
1650+
}
16021651
}

0 commit comments

Comments
 (0)