Skip to content

Commit 586dca8

Browse files
committed
don't decrement if consumerCapacity is 0
1 parent 669934e commit 586dca8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/java/rx/internal/operators/OnSubscribeRedo.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,11 @@ public void onNext(T v) {
238238
child.onNext(v);
239239
while (true) {
240240
long cc = consumerCapacity.get();
241-
if (cc != Long.MAX_VALUE) {
242-
if (consumerCapacity.compareAndSet(cc, cc -1)) {
241+
if (cc == 0) {
242+
// wasn't requested but has arrived anyway
243+
break;
244+
} else if (cc != Long.MAX_VALUE) {
245+
if (consumerCapacity.compareAndSet(cc, cc - 1)) {
243246
break;
244247
}
245248
} else {
@@ -320,10 +323,14 @@ public void onError(Throwable e) {
320323

321324
@Override
322325
public void onNext(Object t) {
326+
// a restart instruction has arrived
323327
if (!isLocked.get() && !child.isUnsubscribed()) {
328+
// if there are outstanding requests
324329
if (consumerCapacity.get() > 0) {
330+
// schedule resubscription
325331
worker.schedule(subscribeToSource);
326332
} else {
333+
// otherwise we indicate that on the next request we should resubscribe
327334
resumeBoundary.compareAndSet(false, true);
328335
}
329336
}

0 commit comments

Comments
 (0)