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:
committed by
Brian Clozel
parent
01bd8b9e01
commit
00617d74de
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user