File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed
main/java/io/reactivex/internal/operators
test/java/io/reactivex/internal/operators Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -62,9 +62,10 @@ public void onSubscribe(Subscription s) {
62
62
}
63
63
@ Override
64
64
public void onNext (T t ) {
65
- if (!done ) {
65
+ if (!done && remaining -- > 0 ) {
66
+ boolean stop = remaining == 0 ;
66
67
actual .onNext (t );
67
- if (-- remaining == 0L ) {
68
+ if (stop ) {
68
69
onComplete ();
69
70
}
70
71
}
Original file line number Diff line number Diff line change 30
30
import io .reactivex .exceptions .TestException ;
31
31
import io .reactivex .internal .subscriptions .*;
32
32
import io .reactivex .schedulers .Schedulers ;
33
+ import io .reactivex .subjects .PublishSubject ;
33
34
import io .reactivex .subscribers .TestSubscriber ;
34
35
35
36
public class OperatorTakeTest {
@@ -420,4 +421,19 @@ public void onNext(Integer t) {
420
421
ts .assertError (TestException .class );
421
422
ts .assertNotComplete ();
422
423
}
424
+
425
+ @ Test
426
+ public void testReentrantTake () {
427
+ PublishSubject <Integer > source = PublishSubject .create ();
428
+
429
+ TestSubscriber <Integer > ts = new TestSubscriber <>();
430
+
431
+ source .take (1 ).doOnNext (v -> source .onNext (2 )).subscribe (ts );
432
+
433
+ source .onNext (1 );
434
+
435
+ ts .assertValue (1 );
436
+ ts .assertNoErrors ();
437
+ ts .assertComplete ();
438
+ }
423
439
}
Original file line number Diff line number Diff line change 31
31
import io .reactivex .exceptions .TestException ;
32
32
import io .reactivex .internal .disposables .EmptyDisposable ;
33
33
import io .reactivex .schedulers .Schedulers ;
34
+ import io .reactivex .subjects .nbp .NbpPublishSubject ;
34
35
import io .reactivex .subscribers .nbp .NbpTestSubscriber ;
35
36
36
37
public class NbpOperatorTakeTest {
@@ -338,4 +339,19 @@ public void onNext(Integer t) {
338
339
ts .assertError (TestException .class );
339
340
ts .assertNotComplete ();
340
341
}
342
+
343
+ @ Test
344
+ public void testReentrantTake () {
345
+ NbpPublishSubject <Integer > source = NbpPublishSubject .create ();
346
+
347
+ NbpTestSubscriber <Integer > ts = new NbpTestSubscriber <>();
348
+
349
+ source .take (1 ).doOnNext (v -> source .onNext (2 )).subscribe (ts );
350
+
351
+ source .onNext (1 );
352
+
353
+ ts .assertValue (1 );
354
+ ts .assertNoErrors ();
355
+ ts .assertComplete ();
356
+ }
341
357
}
You can’t perform that action at this time.
0 commit comments