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.request add ignore for negative requests #2545

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

Subscriber.request add ignore for negative requests #2545

davidmoten opened this issue Jan 28, 2015 · 3 comments

Comments

@davidmoten
Copy link
Collaborator

So that negative requests don't need to be checked by every Operator that supports backpressure why don't we add a check at the start of Subscriber.request:

protected final void request(long n) {
        // ignore zero or negative requests
        if (n <=0) return;
        Producer shouldRequest = null;
        synchronized (this) {
            if (p != null) {
                shouldRequest = p;
            } else {
                requested = n;
            }
        }
        // after releasing lock
        if (shouldRequest != null) {
            shouldRequest.request(n);
        }
    }

Happy to submit PR if has support.

@zsxwing
Copy link
Member

zsxwing commented Jan 28, 2015

Looks a good place to add it. Just a bit comment: Ignore zero but IAE for negative numbers, as per #1956

@davidmoten
Copy link
Collaborator Author

I did wonder about that, and makes sense. I'll make a PR.

@davidmoten
Copy link
Collaborator Author

Looks to me that n = 0 should be allowed through because it may override a default of Long.MAX_VALUE sometimes (asking an upstream producer to produce nothing as opposed to whatever a default might be). I'll make a PR with the n < 0 check only.

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

3 participants