Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriber.OnStart requests should be additive? #2544

Closed
davidmoten opened this issue Jan 28, 2015 · 2 comments
Closed

Subscriber.OnStart requests should be additive? #2544

davidmoten opened this issue Jan 28, 2015 · 2 comments

Comments

@davidmoten
Copy link
Collaborator

For a Subscriber without a Producer, calling

@Override
public void onStart() {
    request(2);
    request(3);
}

does not give 5 requests but 3 only. Shouldn't this be additive? (or at least documented that it is not).

@akarnokd
Copy link
Member

It should be additive and check for overflow. Do you want to submit a new PR or amend #2548?

Edit: However, as your commented, an additive request(0) would never override a max long.

@davidmoten
Copy link
Collaborator Author

I'll submit a new PR, thanks.

Override was probably misleading. A better term would be probably be prevents requested being set to Long.MAX_VALUE. I was referring to the code below from Subscriber where if a request(0) does nothing but return (doesn't set requested to 0) then requested can end up as Long.MAX_VALUE.

 public void setProducer(Producer producer) {
        long toRequest;
        boolean setProducer = false;
        synchronized (this) {
            toRequest = requested;
            p = producer;
            if (op != null) {
                // middle operator ... we pass thru unless a request has been made
                if (toRequest == Long.MIN_VALUE) {
                    // we pass-thru to the next producer as nothing has been requested
                    setProducer = true;
                }

            }
        }
        // do after releasing lock
        if (setProducer) {
            op.setProducer(p);
        } else {
            // we execute the request with whatever has been requested (or Long.MAX_VALUE)
            if (toRequest == Long.MIN_VALUE) {
                p.request(Long.MAX_VALUE);
            } else {
                p.request(toRequest);
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants