Skip to content

Commit 0d69ed8

Browse files
SubscriptionBuilder: simplify and expand on how observer() works
1 parent a7efa05 commit 0d69ed8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

objectbox-java/src/main/java/io/objectbox/reactive/SubscriptionBuilder.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,20 @@ public SubscriptionBuilder<T> on(Scheduler scheduler) {
148148
}
149149

150150
/**
151-
* Sets the observer for this subscription and requests the latest data to be delivered immediately.
152-
* Subscribes to receive data updates. This can be changed by using {@link #single()} or {@link #onlyChanges()}.
151+
* Completes building the subscription by setting a {@link DataObserver} that receives the data.
153152
* <p>
154-
* Results are delivered on a background thread owned by the internal data publisher,
155-
* unless a scheduler was set using {@link #on(Scheduler)}.
153+
* By default, requests the latest data to be delivered immediately and on any future updates. To change this call
154+
* {@link #single()} or {@link #onlyChanges()} before.
156155
* <p>
157-
* The returned {@link DataSubscription} must be canceled once the observer should no longer receive data.
156+
* By default, {@link DataObserver#onData(Object)} is called from an internal background thread. Change this by
157+
* setting a custom scheduler using {@link #on(Scheduler)}. It may also get called for multiple observers at the
158+
* same time. The order in which observers are called is the same as the subscription order, although this may
159+
* change in the future.
160+
* <p>
161+
* Typically, keep a reference to the returned {@link DataSubscription} to avoid it getting garbage collected, to
162+
* keep receiving new data.
163+
* <p>
164+
* Call {@link DataSubscription#cancel()} once the observer should no longer receive data.
158165
*/
159166
public DataSubscription observer(DataObserver<T> observer) {
160167
WeakDataObserver<T> weakObserver = null;

0 commit comments

Comments
 (0)