Skip to content

request(0) is supposed to work? #1956

@zsxwing

Description

@zsxwing

The docs about request doesn't say anything requirement about n

public interface Producer {

    /**
     * Request a certain maximum number of items from this Producer. This is a way of requesting backpressure.
     * To disable backpressure, pass {@code Long.MAX_VALUE} to this method.
     *
     * @param n the maximum number of items you want this Producer to produce, or {@code Long.MAX_VALUE} if you
     *          want the Producer to produce items at its own pace
     */
    public void request(long n);

}
    /**
     * Request a certain maximum number of emitted items from the Observable this Subscriber is subscribed to.
     * This is a way of requesting backpressure. To disable backpressure, pass {@code Long.MAX_VALUE} to this
     * method.
     *
     * @param n the maximum number of items you want the Observable to emit to the Subscriber at this time, or
     *           {@code Long.MAX_VALUE} if you want the Observable to emit items at its own pace
     */
    protected final void request(long n) {

I assume n must be greater than 0. But I also notice I may write something like this occasionally:

long getTheNextRequestNumber() {
  if (...) {
       ...
       return x; // x>0
  } else {
        ...
       return 0;
   }
}

long n = getTheNextRequestNumber();
request(n);

So request(0) is fine? If not, I think it's better to document it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions