Skip to content

Commit

Permalink
don't decrement if consumerCapacity is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmoten committed May 5, 2015
1 parent 669934e commit 586dca8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/rx/internal/operators/OnSubscribeRedo.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,11 @@ public void onNext(T v) {
child.onNext(v);
while (true) {
long cc = consumerCapacity.get();
if (cc != Long.MAX_VALUE) {
if (consumerCapacity.compareAndSet(cc, cc -1)) {
if (cc == 0) {
// wasn't requested but has arrived anyway
break;
} else if (cc != Long.MAX_VALUE) {
if (consumerCapacity.compareAndSet(cc, cc - 1)) {
break;
}
} else {
Expand Down Expand Up @@ -320,10 +323,14 @@ public void onError(Throwable e) {

@Override
public void onNext(Object t) {
// a restart instruction has arrived
if (!isLocked.get() && !child.isUnsubscribed()) {
// if there are outstanding requests
if (consumerCapacity.get() > 0) {
// schedule resubscription
worker.schedule(subscribeToSource);
} else {
// otherwise we indicate that on the next request we should resubscribe
resumeBoundary.compareAndSet(false, true);
}
}
Expand Down

0 comments on commit 586dca8

Please sign in to comment.