Skip to content

Commit f624001

Browse files
authored
2.x: Explain the properties of the XEmitter interfaces in detail (#5844)
1 parent 2875fef commit f624001

File tree

5 files changed

+135
-22
lines changed

5 files changed

+135
-22
lines changed

src/main/java/io/reactivex/CompletableEmitter.java

+27-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,29 @@
2121
* Abstraction over an RxJava {@link CompletableObserver} that allows associating
2222
* a resource with it.
2323
* <p>
24-
* All methods are safe to call from multiple threads.
24+
* All methods are safe to call from multiple threads, but note that there is no guarantee
25+
* whose terminal event will win and get delivered to the downstream.
2526
* <p>
26-
* Calling onComplete or onError multiple times has no effect.
27+
* Calling {@link #onComplete()} multiple times has no effect.
28+
* Calling {@link #onError(Throwable)} multiple times or after {@code onComplete} will route the
29+
* exception into the global error handler via {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)}.
30+
* <p>
31+
* The emitter allows the registration of a single resource, in the form of a {@link Disposable}
32+
* or {@link Cancellable} via {@link #setDisposable(Disposable)} or {@link #setCancellable(Cancellable)}
33+
* respectively. The emitter implementations will dispose/cancel this instance when the
34+
* downstream cancels the flow or after the event generator logic calls
35+
* {@link #onError(Throwable)}, {@link #onComplete()} or when {@link #tryOnError(Throwable)} succeeds.
36+
* <p>
37+
* Only one {@code Disposable} or {@code Cancellable} object can be associated with the emitter at
38+
* a time. Calling either {@code set} method will dispose/cancel any previous object. If there
39+
* is a need for handling multiple resources, one can create a {@link io.reactivex.disposables.CompositeDisposable}
40+
* and associate that with the emitter instead.
41+
* <p>
42+
* The {@link Cancellable} is logically equivalent to {@code Disposable} but allows using cleanup logic that can
43+
* throw a checked exception (such as many {@code close()} methods on Java IO components). Since
44+
* the release of resources happens after the terminal events have been delivered or the sequence gets
45+
* cancelled, exceptions throw within {@code Cancellable} are routed to the global error handler via
46+
* {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)}.
2747
*/
2848
public interface CompletableEmitter {
2949

@@ -53,8 +73,11 @@ public interface CompletableEmitter {
5373
void setCancellable(@Nullable Cancellable c);
5474

5575
/**
56-
* Returns true if the downstream disposed the sequence.
57-
* @return true if the downstream disposed the sequence
76+
* Returns true if the downstream disposed the sequence or the
77+
* emitter was terminated via {@link #onError(Throwable)},
78+
* {@link #onComplete} or a successful {@link #tryOnError(Throwable)}.
79+
* <p>This method is thread-safe.
80+
* @return true if the downstream disposed the sequence or the emitter was terminated
5881
*/
5982
boolean isDisposed();
6083

src/main/java/io/reactivex/FlowableEmitter.java

+26-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,29 @@
2222
* a resource with it and exposes the current number of downstream
2323
* requested amount.
2424
* <p>
25-
* The onNext, onError and onComplete methods should be called
26-
* in a sequential manner, just like the Subscriber's methods.
27-
* Use {@link #serialize()} if you want to ensure this.
25+
* The {@link #onNext(Object)}, {@link #onError(Throwable)}, {@link #tryOnError(Throwable)}
26+
* and {@link #onComplete()} methods should be called in a sequential manner, just like
27+
* the {@link org.reactivestreams.Subscriber Subscriber}'s methods.
28+
* Use the {@code FlowableEmitter} the {@link #serialize()} method returns instead of the original
29+
* {@code FlowableEmitter} instance provided by the generator routine if you want to ensure this.
2830
* The other methods are thread-safe.
31+
* <p>
32+
* The emitter allows the registration of a single resource, in the form of a {@link Disposable}
33+
* or {@link Cancellable} via {@link #setDisposable(Disposable)} or {@link #setCancellable(Cancellable)}
34+
* respectively. The emitter implementations will dispose/cancel this instance when the
35+
* downstream cancels the flow or after the event generator logic calls {@link #onError(Throwable)},
36+
* {@link #onComplete()} or when {@link #tryOnError(Throwable)} succeeds.
37+
* <p>
38+
* Only one {@code Disposable} or {@code Cancellable} object can be associated with the emitter at
39+
* a time. Calling either {@code set} method will dispose/cancel any previous object. If there
40+
* is a need for handling multiple resources, one can create a {@link io.reactivex.disposables.CompositeDisposable}
41+
* and associate that with the emitter instead.
42+
* <p>
43+
* The {@link Cancellable} is logically equivalent to {@code Disposable} but allows using cleanup logic that can
44+
* throw a checked exception (such as many {@code close()} methods on Java IO components). Since
45+
* the release of resources happens after the terminal events have been delivered or the sequence gets
46+
* cancelled, exceptions throw within {@code Cancellable} are routed to the global error handler via
47+
* {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)}.
2948
*
3049
* @param <T> the value type to emit
3150
*/
@@ -53,9 +72,11 @@ public interface FlowableEmitter<T> extends Emitter<T> {
5372
long requested();
5473

5574
/**
56-
* Returns true if the downstream cancelled the sequence.
75+
* Returns true if the downstream cancelled the sequence or the
76+
* emitter was terminated via {@link #onError(Throwable)}, {@link #onComplete} or a
77+
* successful {@link #tryOnError(Throwable)}.
5778
* <p>This method is thread-safe.
58-
* @return true if the downstream cancelled the sequence
79+
* @return true if the downstream cancelled the sequence or the emitter was terminated
5980
*/
6081
boolean isCancelled();
6182

src/main/java/io/reactivex/MaybeEmitter.java

+28-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,29 @@
2121
* Abstraction over an RxJava {@link MaybeObserver} that allows associating
2222
* a resource with it.
2323
* <p>
24-
* All methods are safe to call from multiple threads.
24+
* All methods are safe to call from multiple threads, but note that there is no guarantee
25+
* whose terminal event will win and get delivered to the downstream.
2526
* <p>
26-
* Calling onSuccess, onError or onComplete multiple times has no effect.
27+
* Calling {@link #onSuccess(Object)} or {@link #onComplete()} multiple times has no effect.
28+
* Calling {@link #onError(Throwable)} multiple times or after the other two will route the
29+
* exception into the global error handler via {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)}.
30+
* <p>
31+
* The emitter allows the registration of a single resource, in the form of a {@link Disposable}
32+
* or {@link Cancellable} via {@link #setDisposable(Disposable)} or {@link #setCancellable(Cancellable)}
33+
* respectively. The emitter implementations will dispose/cancel this instance when the
34+
* downstream cancels the flow or after the event generator logic calls {@link #onSuccess(Object)},
35+
* {@link #onError(Throwable)}, {@link #onComplete()} or when {@link #tryOnError(Throwable)} succeeds.
36+
* <p>
37+
* Only one {@code Disposable} or {@code Cancellable} object can be associated with the emitter at
38+
* a time. Calling either {@code set} method will dispose/cancel any previous object. If there
39+
* is a need for handling multiple resources, one can create a {@link io.reactivex.disposables.CompositeDisposable}
40+
* and associate that with the emitter instead.
41+
* <p>
42+
* The {@link Cancellable} is logically equivalent to {@code Disposable} but allows using cleanup logic that can
43+
* throw a checked exception (such as many {@code close()} methods on Java IO components). Since
44+
* the release of resources happens after the terminal events have been delivered or the sequence gets
45+
* cancelled, exceptions throw within {@code Cancellable} are routed to the global error handler via
46+
* {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)}.
2747
*
2848
* @param <T> the value type to emit
2949
*/
@@ -61,8 +81,12 @@ public interface MaybeEmitter<T> {
6181
void setCancellable(@Nullable Cancellable c);
6282

6383
/**
64-
* Returns true if the downstream cancelled the sequence.
65-
* @return true if the downstream cancelled the sequence
84+
* Returns true if the downstream disposed the sequence or the
85+
* emitter was terminated via {@link #onSuccess(Object)}, {@link #onError(Throwable)},
86+
* {@link #onComplete} or a
87+
* successful {@link #tryOnError(Throwable)}.
88+
* <p>This method is thread-safe.
89+
* @return true if the downstream disposed the sequence or the emitter was terminated
6690
*/
6791
boolean isDisposed();
6892

src/main/java/io/reactivex/ObservableEmitter.java

+27-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,29 @@
2121
* Abstraction over an RxJava {@link Observer} that allows associating
2222
* a resource with it.
2323
* <p>
24-
* The onNext, onError and onComplete methods should be called
25-
* in a sequential manner, just like the Observer's methods.
26-
* Use {@link #serialize()} if you want to ensure this.
24+
* The {@link #onNext(Object)}, {@link #onError(Throwable)}, {@link #tryOnError(Throwable)}
25+
* and {@link #onComplete()} methods should be called in a sequential manner, just like the
26+
* {@link Observer}'s methods should be.
27+
* Use the {@code ObservableEmitter} the {@link #serialize()} method returns instead of the original
28+
* {@code ObservableEmitter} instance provided by the generator routine if you want to ensure this.
2729
* The other methods are thread-safe.
30+
* <p>
31+
* The emitter allows the registration of a single resource, in the form of a {@link Disposable}
32+
* or {@link Cancellable} via {@link #setDisposable(Disposable)} or {@link #setCancellable(Cancellable)}
33+
* respectively. The emitter implementations will dispose/cancel this instance when the
34+
* downstream cancels the flow or after the event generator logic calls {@link #onError(Throwable)},
35+
* {@link #onComplete()} or when {@link #tryOnError(Throwable)} succeeds.
36+
* <p>
37+
* Only one {@code Disposable} or {@code Cancellable} object can be associated with the emitter at
38+
* a time. Calling either {@code set} method will dispose/cancel any previous object. If there
39+
* is a need for handling multiple resources, one can create a {@link io.reactivex.disposables.CompositeDisposable}
40+
* and associate that with the emitter instead.
41+
* <p>
42+
* The {@link Cancellable} is logically equivalent to {@code Disposable} but allows using cleanup logic that can
43+
* throw a checked exception (such as many {@code close()} methods on Java IO components). Since
44+
* the release of resources happens after the terminal events have been delivered or the sequence gets
45+
* cancelled, exceptions throw within {@code Cancellable} are routed to the global error handler via
46+
* {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)}.
2847
*
2948
* @param <T> the value type to emit
3049
*/
@@ -45,8 +64,11 @@ public interface ObservableEmitter<T> extends Emitter<T> {
4564
void setCancellable(@Nullable Cancellable c);
4665

4766
/**
48-
* Returns true if the downstream disposed the sequence.
49-
* @return true if the downstream disposed the sequence
67+
* Returns true if the downstream disposed the sequence or the
68+
* emitter was terminated via {@link #onError(Throwable)}, {@link #onComplete} or a
69+
* successful {@link #tryOnError(Throwable)}.
70+
* <p>This method is thread-safe.
71+
* @return true if the downstream disposed the sequence or the emitter was terminated
5072
*/
5173
boolean isDisposed();
5274

src/main/java/io/reactivex/SingleEmitter.java

+27-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,29 @@
2121
* Abstraction over an RxJava {@link SingleObserver} that allows associating
2222
* a resource with it.
2323
* <p>
24-
* All methods are safe to call from multiple threads.
24+
* All methods are safe to call from multiple threads, but note that there is no guarantee
25+
* whose terminal event will win and get delivered to the downstream.
2526
* <p>
26-
* Calling onSuccess or onError multiple times has no effect.
27+
* Calling {@link #onSuccess(Object)} multiple times has no effect.
28+
* Calling {@link #onError(Throwable)} multiple times or after {@code onSuccess} will route the
29+
* exception into the global error handler via {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)}.
30+
* <p>
31+
* The emitter allows the registration of a single resource, in the form of a {@link Disposable}
32+
* or {@link Cancellable} via {@link #setDisposable(Disposable)} or {@link #setCancellable(Cancellable)}
33+
* respectively. The emitter implementations will dispose/cancel this instance when the
34+
* downstream cancels the flow or after the event generator logic calls {@link #onSuccess(Object)},
35+
* {@link #onError(Throwable)}, or when {@link #tryOnError(Throwable)} succeeds.
36+
* <p>
37+
* Only one {@code Disposable} or {@code Cancellable} object can be associated with the emitter at
38+
* a time. Calling either {@code set} method will dispose/cancel any previous object. If there
39+
* is a need for handling multiple resources, one can create a {@link io.reactivex.disposables.CompositeDisposable}
40+
* and associate that with the emitter instead.
41+
* <p>
42+
* The {@link Cancellable} is logically equivalent to {@code Disposable} but allows using cleanup logic that can
43+
* throw a checked exception (such as many {@code close()} methods on Java IO components). Since
44+
* the release of resources happens after the terminal events have been delivered or the sequence gets
45+
* cancelled, exceptions throw within {@code Cancellable} are routed to the global error handler via
46+
* {@link io.reactivex.plugins.RxJavaPlugins#onError(Throwable)}.
2747
*
2848
* @param <T> the value type to emit
2949
*/
@@ -56,8 +76,11 @@ public interface SingleEmitter<T> {
5676
void setCancellable(@Nullable Cancellable c);
5777

5878
/**
59-
* Returns true if the downstream cancelled the sequence.
60-
* @return true if the downstream cancelled the sequence
79+
* Returns true if the downstream disposed the sequence or the
80+
* emitter was terminated via {@link #onSuccess(Object)}, {@link #onError(Throwable)},
81+
* or a successful {@link #tryOnError(Throwable)}.
82+
* <p>This method is thread-safe.
83+
* @return true if the downstream disposed the sequence or the emitter was terminated
6184
*/
6285
boolean isDisposed();
6386

0 commit comments

Comments
 (0)