21
21
* Abstraction over an RxJava {@link Observer} that allows associating
22
22
* a resource with it.
23
23
* <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.
27
29
* 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)}.
28
47
*
29
48
* @param <T> the value type to emit
30
49
*/
@@ -45,8 +64,11 @@ public interface ObservableEmitter<T> extends Emitter<T> {
45
64
void setCancellable (@ Nullable Cancellable c );
46
65
47
66
/**
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
50
72
*/
51
73
boolean isDisposed ();
52
74
0 commit comments