File tree 3 files changed +73
-12
lines changed
main/java/io/reactivex/internal/operators/observable
test/java/io/reactivex/internal/operators
3 files changed +73
-12
lines changed Original file line number Diff line number Diff line change @@ -334,6 +334,7 @@ void drainLoop() {
334
334
if (checkTerminate ()) {
335
335
return ;
336
336
}
337
+ int innerCompleted = 0 ;
337
338
SimplePlainQueue <U > svq = queue ;
338
339
339
340
if (svq != null ) {
@@ -349,9 +350,18 @@ void drainLoop() {
349
350
}
350
351
351
352
child .onNext (o );
353
+ innerCompleted ++;
352
354
}
353
355
}
354
356
357
+ if (innerCompleted != 0 ) {
358
+ if (maxConcurrency != Integer .MAX_VALUE ) {
359
+ subscribeMore (innerCompleted );
360
+ innerCompleted = 0 ;
361
+ }
362
+ continue ;
363
+ }
364
+
355
365
boolean d = done ;
356
366
svq = queue ;
357
367
InnerObserver <?, ?>[] inner = observers .get ();
@@ -376,7 +386,6 @@ void drainLoop() {
376
386
return ;
377
387
}
378
388
379
- int innerCompleted = 0 ;
380
389
if (n != 0 ) {
381
390
long startId = lastId ;
382
391
int index = lastIndex ;
@@ -463,27 +472,33 @@ void drainLoop() {
463
472
464
473
if (innerCompleted != 0 ) {
465
474
if (maxConcurrency != Integer .MAX_VALUE ) {
466
- while (innerCompleted -- != 0 ) {
467
- ObservableSource <? extends U > p ;
468
- synchronized (this ) {
469
- p = sources .poll ();
470
- if (p == null ) {
471
- wip --;
472
- continue ;
473
- }
474
- }
475
- subscribeInner (p );
476
- }
475
+ subscribeMore (innerCompleted );
476
+ innerCompleted = 0 ;
477
477
}
478
478
continue ;
479
479
}
480
+
480
481
missed = addAndGet (-missed );
481
482
if (missed == 0 ) {
482
483
break ;
483
484
}
484
485
}
485
486
}
486
487
488
+ void subscribeMore (int innerCompleted ) {
489
+ while (innerCompleted -- != 0 ) {
490
+ ObservableSource <? extends U > p ;
491
+ synchronized (this ) {
492
+ p = sources .poll ();
493
+ if (p == null ) {
494
+ wip --;
495
+ continue ;
496
+ }
497
+ }
498
+ subscribeInner (p );
499
+ }
500
+ }
501
+
487
502
boolean checkTerminate () {
488
503
if (cancelled ) {
489
504
return true ;
Original file line number Diff line number Diff line change @@ -1157,4 +1157,27 @@ public void innerErrorsMainCancelled() {
1157
1157
1158
1158
assertFalse ("Has subscribers?" , pp1 .hasSubscribers ());
1159
1159
}
1160
+
1161
+ @ Test (timeout = 5000 )
1162
+ public void mixedScalarAsync () {
1163
+ for (int i = 0 ; i < TestHelper .RACE_DEFAULT_LOOPS ; i ++) {
1164
+ Flowable
1165
+ .range (0 , 20 )
1166
+ .flatMap (new Function <Integer , Publisher <?>>() {
1167
+ @ Override
1168
+ public Publisher <?> apply (Integer integer ) throws Exception {
1169
+ if (integer % 5 != 0 ) {
1170
+ return Flowable
1171
+ .just (integer );
1172
+ }
1173
+
1174
+ return Flowable
1175
+ .just (-integer )
1176
+ .observeOn (Schedulers .computation ());
1177
+ }
1178
+ }, false , 1 )
1179
+ .ignoreElements ()
1180
+ .blockingAwait ();
1181
+ }
1182
+ }
1160
1183
}
Original file line number Diff line number Diff line change @@ -1118,4 +1118,27 @@ public void innerErrorsMainCancelled() {
1118
1118
1119
1119
assertFalse ("Has subscribers?" , ps1 .hasObservers ());
1120
1120
}
1121
+
1122
+ @ Test (timeout = 5000 )
1123
+ public void mixedScalarAsync () {
1124
+ for (int i = 0 ; i < TestHelper .RACE_DEFAULT_LOOPS ; i ++) {
1125
+ Observable
1126
+ .range (0 , 20 )
1127
+ .flatMap (new Function <Integer , ObservableSource <?>>() {
1128
+ @ Override
1129
+ public ObservableSource <?> apply (Integer integer ) throws Exception {
1130
+ if (integer % 5 != 0 ) {
1131
+ return Observable
1132
+ .just (integer );
1133
+ }
1134
+
1135
+ return Observable
1136
+ .just (-integer )
1137
+ .observeOn (Schedulers .computation ());
1138
+ }
1139
+ }, false , 1 )
1140
+ .ignoreElements ()
1141
+ .blockingAwait ();
1142
+ }
1143
+ }
1121
1144
}
You can’t perform that action at this time.
0 commit comments