File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
main/java/rx/internal/operators
test/java/rx/internal/operators Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -185,7 +185,8 @@ void pollQueue() {
185
185
counter = 1 ;
186
186
long produced = 0 ;
187
187
long r = requested ;
188
- while (!child .isUnsubscribed ()) {
188
+ boolean isUnsubscribed ;
189
+ while (!(isUnsubscribed = child .isUnsubscribed ())) {
189
190
Throwable error ;
190
191
if (finished ) {
191
192
if ((error = this .error ) != null ) {
@@ -214,6 +215,8 @@ void pollQueue() {
214
215
break ;
215
216
}
216
217
}
218
+ if (isUnsubscribed )
219
+ return ;
217
220
if (produced > 0 && requested != Long .MAX_VALUE ) {
218
221
REQUESTED .addAndGet (this , -produced );
219
222
}
Original file line number Diff line number Diff line change 26
26
import static org .mockito .Mockito .times ;
27
27
import static org .mockito .Mockito .verify ;
28
28
29
+ import java .util .ArrayList ;
29
30
import java .util .Arrays ;
31
+ import java .util .Collections ;
30
32
import java .util .Iterator ;
31
33
import java .util .List ;
32
34
import java .util .concurrent .CountDownLatch ;
@@ -765,4 +767,42 @@ public void onNext(Integer t) {
765
767
766
768
}
767
769
770
+ @ Test
771
+ public void testNoMoreRequestsAfterUnsubscribe () throws InterruptedException {
772
+ final CountDownLatch latch = new CountDownLatch (1 );
773
+ final List <Long > requests = Collections .synchronizedList (new ArrayList <Long >());
774
+ Observable .range (1 , 1000000 )
775
+ .doOnRequest (new Action1 <Long >() {
776
+
777
+ @ Override
778
+ public void call (Long n ) {
779
+ requests .add (n );
780
+ }
781
+ })
782
+ .observeOn (Schedulers .io ())
783
+ .subscribe (new Subscriber <Integer >() {
784
+
785
+ @ Override
786
+ public void onStart () {
787
+ request (1 );
788
+ }
789
+
790
+ @ Override
791
+ public void onCompleted () {
792
+ }
793
+
794
+ @ Override
795
+ public void onError (Throwable e ) {
796
+ }
797
+
798
+ @ Override
799
+ public void onNext (Integer t ) {
800
+ unsubscribe ();
801
+ latch .countDown ();
802
+ }
803
+ });
804
+ assertTrue (latch .await (10 , TimeUnit .SECONDS ));
805
+ assertEquals (1 , requests .size ());
806
+ }
807
+
768
808
}
You can’t perform that action at this time.
0 commit comments