File tree Expand file tree Collapse file tree 2 files changed +44
-6
lines changed
main/java/io/reactivex/internal/operators/flowable
test/java/io/reactivex/internal/operators/flowable Expand file tree Collapse file tree 2 files changed +44
-6
lines changed Original file line number Diff line number Diff line change @@ -709,17 +709,25 @@ public T poll() {
709
709
produced ++;
710
710
return v ;
711
711
}
712
- int p = produced ;
713
- if (p != 0 ) {
714
- produced = 0 ;
715
- parent .upstream .request (p );
716
- }
712
+ tryReplenish ();
717
713
return null ;
718
714
}
719
715
720
716
@ Override
721
717
public boolean isEmpty () {
722
- return queue .isEmpty ();
718
+ if (queue .isEmpty ()) {
719
+ tryReplenish ();
720
+ return true ;
721
+ }
722
+ return false ;
723
+ }
724
+
725
+ void tryReplenish () {
726
+ int p = produced ;
727
+ if (p != 0 ) {
728
+ produced = 0 ;
729
+ parent .upstream .request (p );
730
+ }
723
731
}
724
732
725
733
@ Override
Original file line number Diff line number Diff line change @@ -2286,4 +2286,34 @@ public void run() {
2286
2286
}
2287
2287
}
2288
2288
}
2289
+
2290
+ @ Test
2291
+ public void fusedParallelGroupProcessing () {
2292
+ Flowable .range (0 , 500000 )
2293
+ .subscribeOn (Schedulers .single ())
2294
+ .groupBy (new Function <Integer , Integer >() {
2295
+ @ Override
2296
+ public Integer apply (Integer i ) {
2297
+ return i % 2 ;
2298
+ }
2299
+ })
2300
+ .flatMap (new Function <GroupedFlowable <Integer , Integer >, Publisher <Integer >>() {
2301
+ @ Override
2302
+ public Publisher <Integer > apply (GroupedFlowable <Integer , Integer > g ) {
2303
+ return g .getKey () == 0
2304
+ ? g
2305
+ .parallel ()
2306
+ .runOn (Schedulers .computation ())
2307
+ .map (Functions .<Integer >identity ())
2308
+ .sequential ()
2309
+ : g .map (Functions .<Integer >identity ()) // no need to use hide
2310
+ ;
2311
+ }
2312
+ })
2313
+ .test ()
2314
+ .awaitDone (20 , TimeUnit .SECONDS )
2315
+ .assertValueCount (500000 )
2316
+ .assertComplete ()
2317
+ .assertNoErrors ();
2318
+ }
2289
2319
}
You can’t perform that action at this time.
0 commit comments