| 1 |
/* |
| 2 |
* Copyright (c) 2016-present, RxJava Contributors. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 |
* the License for the specific language governing permissions and limitations under the License. |
| 12 |
*/ |
| 13 |
|
| 14 |
package io.reactivex.rxjava3.operators; |
| 15 |
|
| 16 |
import org.reactivestreams.Subscription; |
| 17 |
|
| 18 |
import io.reactivex.rxjava3.annotations.NonNull; |
| 19 |
|
| 20 |
/** |
| 21 |
* An interface extending {@link SimpleQueue} and {@link Subscription} and allows negotiating |
| 22 |
* the fusion mode between subsequent operators of the {@link io.reactivex.rxjava3.core.Flowable Flowable} base reactive type. |
| 23 |
* <p> |
| 24 |
* The negotiation happens in subscription time when the upstream |
| 25 |
* calls the {@code onSubscribe} with an instance of this interface. The |
| 26 |
* downstream has then the obligation to call {@link #requestFusion(int)} |
| 27 |
* with the appropriate mode before calling {@code request()}. |
| 28 |
* <p> |
| 29 |
* In <b>synchronous fusion</b>, all upstream values are either already available or is generated |
| 30 |
* when {@link #poll()} is called synchronously. When the {@link #poll()} returns null, |
| 31 |
* that is the indication if a terminated stream. Downstream should not call {@link #request(long)} |
| 32 |
* in this mode. In this mode, the upstream won't call the onXXX methods. |
| 33 |
* <p> |
| 34 |
* In <b>asynchronous fusion</b>, upstream values may become available to {@link #poll()} eventually. |
| 35 |
* Upstream signals {@code onError()} and {@code onComplete()} as usual, however, |
| 36 |
* {@code onNext} will be called with {@code null} instead of the actual value. |
| 37 |
* Downstream should treat such onNext as indication that {@link #poll()} can be called. |
| 38 |
* In this mode, the downstream still has to call {@link #request(long)} |
| 39 |
* to indicate it is prepared to receive more values. |
| 40 |
* <p> |
| 41 |
* The general rules for consuming the {@link SimpleQueue} interface: |
| 42 |
* <ul> |
| 43 |
* <li> {@link #poll()} and {@link #clear()} has to be called sequentially (from within a serializing drain-loop).</li> |
| 44 |
* <li>In addition, callers of {@link #poll()} should be prepared to catch exceptions.</li> |
| 45 |
* <li>Due to how computation attaches to the {@link #poll()}, {@link #poll()} may return |
| 46 |
* {@code null} even if a preceding {@link #isEmpty()} returned false.</li> |
| 47 |
* </ul> |
| 48 |
* <p> |
| 49 |
* Implementations should only allow calling the following methods and the rest of the |
| 50 |
* {@link SimpleQueue} interface methods should throw {@link UnsupportedOperationException}: |
| 51 |
* <ul> |
| 52 |
* <li>{@link #poll()}</li> |
| 53 |
* <li>{@link #isEmpty()}</li> |
| 54 |
* <li>{@link #clear()}</li> |
| 55 |
* </ul> |
| 56 |
* @param <T> the value type transmitted through the queue |
| 57 |
* @see QueueDisposable |
| 58 |
* @since 3.1.1 |
| 59 |
*/ |
| 60 |
public interface QueueSubscription<@NonNull T> extends QueueFuseable<T>, Subscription { |
| 61 |
} |