Fix AbstractRequestBodyPublisher to comply with the spec

As per specification "The Subscription MUST allow the Subscriber to
call Subscription.request synchronously from within onNext or
onSubscribe". With the current implementation if Subscription.request
is called more than once when Subscriber.onSubscribe ISE will be
thrown - java.lang.IllegalStateException: DEMAND.
With this fix the implementation will not throw ISE and will allow
many invocations of Subscription.request when
Subscriber.onSubscribe.
This commit is contained in:
Violeta Georgieva
2016-09-02 11:19:56 +03:00
committed by Brian Clozel
parent 01bd8b9e01
commit 00617d74de
2 changed files with 94 additions and 0 deletions

View File

@@ -252,6 +252,13 @@ abstract class AbstractRequestBodyPublisher implements Publisher<DataBuffer> {
* {@link #NO_DEMAND} if there is no demand.
*/
DEMAND {
@Override
void request(AbstractRequestBodyPublisher publisher, long n) {
if (Operators.checkRequest(n, publisher.subscriber)) {
Operators.addAndGet(publisher.demand, n);
}
}
@Override
void onDataAvailable(AbstractRequestBodyPublisher publisher) {
if (publisher.changeState(this, READING)) {