File tree Expand file tree Collapse file tree 3 files changed +53
-6
lines changed Expand file tree Collapse file tree 3 files changed +53
-6
lines changed Original file line number Diff line number Diff line change 22
22
import rx .exceptions .Exceptions ;
23
23
import rx .functions .Action1 ;
24
24
import rx .internal .operators .NotificationLite ;
25
+ import rx .internal .producers .SingleProducer ;
25
26
import rx .subjects .SubjectSubscriptionManager .SubjectObserver ;
26
27
27
28
/**
@@ -68,9 +69,13 @@ public static <T> AsyncSubject<T> create() {
68
69
public void call (SubjectObserver <T > o ) {
69
70
Object v = state .getLatest ();
70
71
NotificationLite <T > nl = state .nl ;
71
- o .accept (v , nl );
72
- if (v == null || (!nl .isCompleted (v ) && !nl .isError (v ))) {
72
+ if (v == null || nl .isCompleted (v )) {
73
73
o .onCompleted ();
74
+ } else
75
+ if (nl .isError (v )) {
76
+ o .onError (nl .getError (v ));
77
+ } else {
78
+ o .actual .setProducer (new SingleProducer <T >(o .actual , nl .getValue (v )));
74
79
}
75
80
}
76
81
};
@@ -97,8 +102,7 @@ public void onCompleted() {
97
102
if (last == nl .completed ()) {
98
103
bo .onCompleted ();
99
104
} else {
100
- bo .onNext (nl .getValue (last ));
101
- bo .onCompleted ();
105
+ bo .actual .setProducer (new SingleProducer <T >(bo .actual , nl .getValue (last )));
102
106
}
103
107
}
104
108
}
Original file line number Diff line number Diff line change @@ -203,7 +203,7 @@ public State remove(SubjectObserver o) {
203
203
*/
204
204
protected static final class SubjectObserver <T > implements Observer <T > {
205
205
/** The actual Observer. */
206
- final Observer <? super T > actual ;
206
+ final Subscriber <? super T > actual ;
207
207
/** Was the emitFirst run? Guarded by this. */
208
208
boolean first = true ;
209
209
/** Guarded by this. */
@@ -215,7 +215,7 @@ protected static final class SubjectObserver<T> implements Observer<T> {
215
215
protected volatile boolean caughtUp ;
216
216
/** Indicate where the observer is at replaying. */
217
217
private volatile Object index ;
218
- public SubjectObserver (Observer <? super T > actual ) {
218
+ public SubjectObserver (Subscriber <? super T > actual ) {
219
219
this .actual = actual ;
220
220
}
221
221
@ Override
Original file line number Diff line number Diff line change @@ -430,4 +430,47 @@ public void testAsyncSubjectValueError() {
430
430
assertNull (async .getValue ());
431
431
assertFalse (async .hasValue ());
432
432
}
433
+
434
+ @ Test
435
+ public void backpressureOnline () {
436
+ TestSubscriber <Integer > ts = TestSubscriber .create (0 );
437
+
438
+ AsyncSubject <Integer > subject = AsyncSubject .create ();
439
+
440
+ subject .subscribe (ts );
441
+
442
+ subject .onNext (1 );
443
+ subject .onCompleted ();
444
+
445
+ ts .assertNoValues ();
446
+ ts .assertNoErrors ();
447
+ ts .assertNotCompleted ();
448
+
449
+ ts .requestMore (1 );
450
+
451
+ ts .assertValue (1 );
452
+ ts .assertCompleted ();
453
+ ts .assertNoErrors ();
454
+ }
455
+
456
+ @ Test
457
+ public void backpressureOffline () {
458
+ TestSubscriber <Integer > ts = TestSubscriber .create (0 );
459
+
460
+ AsyncSubject <Integer > subject = AsyncSubject .create ();
461
+ subject .onNext (1 );
462
+ subject .onCompleted ();
463
+
464
+ subject .subscribe (ts );
465
+
466
+ ts .assertNoValues ();
467
+ ts .assertNoErrors ();
468
+ ts .assertNotCompleted ();
469
+
470
+ ts .requestMore (1 );
471
+
472
+ ts .assertValue (1 );
473
+ ts .assertCompleted ();
474
+ ts .assertNoErrors ();
475
+ }
433
476
}
You can’t perform that action at this time.
0 commit comments