|
44 | 44 | import rx.Producer;
|
45 | 45 | import rx.Scheduler;
|
46 | 46 | import rx.Subscriber;
|
| 47 | +import rx.exceptions.MissingBackpressureException; |
47 | 48 | import rx.functions.Action0;
|
48 | 49 | import rx.functions.Func1;
|
49 | 50 | import rx.functions.Func2;
|
@@ -238,11 +239,16 @@ public void onNext(T v) {
|
238 | 239 | child.onNext(v);
|
239 | 240 | while (true) {
|
240 | 241 | long cc = consumerCapacity.get();
|
241 |
| - if (cc != Long.MAX_VALUE) { |
242 |
| - if (consumerCapacity.compareAndSet(cc, cc -1)) { |
| 242 | + if (cc == 0) { |
| 243 | + child.onError(new MissingBackpressureException( |
| 244 | + "an item has arrived to this operator that was not requested, " |
| 245 | + + "please use backpressure aware operators upstream (or append .onBackpressureBuffer() or similar)")); |
| 246 | + break; |
| 247 | + } else if (cc != Long.MAX_VALUE) { |
| 248 | + if (consumerCapacity.compareAndSet(cc, cc - 1)) { |
243 | 249 | break;
|
244 | 250 | }
|
245 |
| - } else { |
| 251 | + } else { |
246 | 252 | break;
|
247 | 253 | }
|
248 | 254 | }
|
@@ -320,10 +326,14 @@ public void onError(Throwable e) {
|
320 | 326 |
|
321 | 327 | @Override
|
322 | 328 | public void onNext(Object t) {
|
| 329 | + // a restart instruction has arrived |
323 | 330 | if (!isLocked.get() && !child.isUnsubscribed()) {
|
| 331 | + // if there are outstanding requests |
324 | 332 | if (consumerCapacity.get() > 0) {
|
| 333 | + // schedule resubscription |
325 | 334 | worker.schedule(subscribeToSource);
|
326 | 335 | } else {
|
| 336 | + // otherwise we indicate that on the next request we should resubscribe |
327 | 337 | resumeBoundary.compareAndSet(false, true);
|
328 | 338 | }
|
329 | 339 | }
|
|
0 commit comments