request(0) in Flow.Subscription and in SubmissionPublisher

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

request(0) in Flow.Subscription and in SubmissionPublisher

Dávid Karnok
Hi,

according to the Reactive-Streams specification, requesting non-positive value is forbidden and must be rewarded with an onError:

> §3.9: While the Subscription is not cancelled, Subscription.request(long n) MUST signal onError with a java.lang.IllegalArgumentException if the argument is <= 0. The cause message MUST include a reference to this rule and/or quote the full rule.

However, the Flow.Subscription essentially ignores 0:

> If {@code n} is
> negative, the Subscriber will receive an {@code onError}
> signal with an {@link IllegalArgumentException} argument.
> Otherwise, the Subscriber will receive up to {@code n}
> additional {@code onNext} invocations (or fewer if
> terminated)


SubmissionPublisher<Integer> sp = new SubmissionPublisher<>(Runnable::run, 128);
Throwable[] err = { null };

sp.subscribe(new Flow.Subscriber<Integer>() {
@Override
public void onSubscribe(Flow.Subscription subscription) {
subscription.request(0L);
}

@Override
public void onNext(Integer item) {

}

@Override
public void onError(Throwable throwable) {
err[0] = throwable;
}

@Override
public void onComplete() {

}
});

assertNotNull(err[0]);

Was this a deliberate change?

--
Best regards,
David Karnok

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest