/** * <p>Creates a Publisher that sends the request when a Subscriber requests the response * via {@link Subscription#request(long)}, processing the response content with the given * function.</p> * <p>Applications must subscribe (possibly asynchronously) to the response content Publisher, * even if it is known that the response has no content, to receive the response success/failure * events.</p> * * @param contentFn the function that processes the response content * @param <T> the element type of the processed response content * @return a Publisher for the processed content */ public <T> Publisher<T> response(BiFunction<ReactiveResponse, Publisher<ContentChunk>, Publisher<T>> contentFn) { return new ResponseListenerPublisher<>(this, contentFn); }
@Override public void onNext(T t) { downStreamOnNext(t); }
@Override protected void onRequest(Subscriber<? super T> subscriber, long n) { boolean send; synchronized (this) { send = !requestSent; requestSent = true; } if (send) { send(); } super.onRequest(subscriber, n); }
@Override public void onComplete(Result result) { if (result.isSucceeded()) { content.complete(); } else { Throwable failure = result.getFailure(); if (!content.fail(failure)) { if (!responseReceived) { onError(failure); } } } }
@Override protected void onRequest(Subscriber<? super T> subscriber, long n) { boolean send; synchronized (this) { send = !requestSent; requestSent = true; } if (send) { send(); } super.onRequest(subscriber, n); }
@Override public void onComplete(Result result) { if (result.isSucceeded()) { content.complete(); } else { Throwable failure = result.getFailure(); if (!content.fail(failure)) { if (!responseReceived) { onError(failure); } } } }
@Override public void onNext(T t) { downStreamOnNext(t); }
/** * <p>Creates a Publisher that sends the request when a Subscriber requests the response * via {@link Subscription#request(long)}, processing the response content with the given * function.</p> * <p>Applications must subscribe (possibly asynchronously) to the response content Publisher, * even if it is known that the response has no content, to receive the response success/failure * events.</p> * * @param contentFn the function that processes the response content * @param <T> the element type of the processed response content * @return a Publisher for the processed content */ public <T> Publisher<T> response(BiFunction<ReactiveResponse, Publisher<ContentChunk>, Publisher<T>> contentFn) { return new ResponseListenerPublisher<>(this, contentFn); }