File tree 2 files changed +42
-1
lines changed
rxjava-core/src/main/java/rx/operators
2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -187,8 +187,11 @@ public void emitChunk(Chunk<T, C> chunk) {
187
187
return ;
188
188
}
189
189
190
- subscription .unsubscribe ();
190
+ // Fixed issue 428.
191
+ // As unsubscribe will cancel the Future, and the currrent thread's interrupt status
192
+ // will be set. So we need to emit the chunk before unsubscribe.
191
193
super .emitChunk (chunk );
194
+ subscription .unsubscribe ();
192
195
createChunk ();
193
196
}
194
197
Original file line number Diff line number Diff line change 15
15
*/
16
16
package rx .operators ;
17
17
18
+ import static org .junit .Assert .assertFalse ;
19
+
18
20
import java .util .ArrayList ;
19
21
import java .util .List ;
22
+ import java .util .concurrent .CountDownLatch ;
20
23
import java .util .concurrent .TimeUnit ;
21
24
22
25
import org .junit .Before ;
37
40
import rx .util .Opening ;
38
41
import rx .util .Openings ;
39
42
import rx .util .functions .Action0 ;
43
+ import rx .util .functions .Action1 ;
40
44
import rx .util .functions .Func0 ;
41
45
import rx .util .functions .Func1 ;
42
46
@@ -631,6 +635,40 @@ public Subscription onSubscribe(Observer<? super Closing> observer) {
631
635
inOrder .verify (observer , Mockito .times (1 )).onCompleted ();
632
636
}
633
637
638
+ @ Test
639
+ public void testLongTimeAction () throws InterruptedException {
640
+ final CountDownLatch latch = new CountDownLatch (1 );
641
+ LongTimeAction action = new LongTimeAction (latch );
642
+ Observable .from (1 ).buffer (10 , TimeUnit .MILLISECONDS , 10 )
643
+ .subscribe (action );
644
+ latch .await ();
645
+ assertFalse (action .fail );
646
+ }
647
+
648
+ private static class LongTimeAction implements Action1 <List <Integer >> {
649
+
650
+ CountDownLatch latch ;
651
+ boolean fail = false ;
652
+
653
+ public LongTimeAction (CountDownLatch latch ) {
654
+ this .latch = latch ;
655
+ }
656
+
657
+ @ Override
658
+ public void call (List <Integer > t1 ) {
659
+ try {
660
+ if (fail ) {
661
+ return ;
662
+ }
663
+ Thread .sleep (200 );
664
+ } catch (InterruptedException e ) {
665
+ fail = true ;
666
+ } finally {
667
+ latch .countDown ();
668
+ }
669
+ }
670
+ }
671
+
634
672
private List <String > list (String ... args ) {
635
673
List <String > list = new ArrayList <String >();
636
674
for (String arg : args ) {
You can’t perform that action at this time.
0 commit comments