SubscriptionSet

A subscription set is an immutable view of all current Subscriptions for a given Realm that has been configured for Flexible Sync.

Flexible Sync is a way of defining which data gets synchronized to and from the device using RealmQuerys. The query and its metadata are represented by a Subscription.

A subscription set thus defines all the data that is available to the device and being synchronized with the server. If the subscription set encounters an error, e.g. by containing an invalid query, the entire subscription set will enter an SubscriptionSetState.ERROR state, and no synchronization will happen until the error has been fixed.

If a subscription is removed, so is the corresponding data, but it is only removed from the device. It isn't deleted on the server.

It is possible to modify a subscription set while offline, but a modification isn't accepted by the server before BaseSubscriptionSet.state returns SubscriptionSetState.COMPLETE, which requires that the device has been online.

It is possible to wait for the subscription set to be synchronized with the server by using waitForSynchronization.

Properties

Link copied to clipboard
abstract val errorMessage: String?

If state returns SubscriptionSetState.ERROR, this method will return the reason. Errors can be fixed by modifying the subscription accordingly and then call SubscriptionSet.waitForSynchronization.

Link copied to clipboard
abstract val size: Int

The number of subscriptions currently in this subscription set.

Link copied to clipboard

The current state of the SubscriptionSet. See SubscriptionSetState for more details about each state.

Functions

Link copied to clipboard
abstract fun close()
Link copied to clipboard
abstract fun findByName(name: String): Subscription?

Find the subscription with a given name.

Link copied to clipboard
abstract fun <T : RealmObject> findByQuery(query: RealmQuery<T>): Subscription?

Find the first subscription that contains the given query. It is possible for multiple named subscriptions to contain the same query.

Link copied to clipboard
abstract operator fun iterator(): Iterator<Subscription>
Link copied to clipboard
abstract fun refresh(): SubscriptionSet<T>

Refresh the state of the subscription set, so it reflect the latest underlying state of the subscriptions.

Link copied to clipboard
abstract suspend fun update(block: MutableSubscriptionSet.(realm: T) -> Unit): SubscriptionSet<T>

Modify the subscription set. If an exception is thrown during the update, no changes will be applied. If the update succeeds, this subscription set is updated with the modified state.

Link copied to clipboard
abstract suspend fun waitForSynchronization(timeout: Duration = Duration.INFINITE): Boolean

Wait for the subscription set to synchronize with the server. It will return when the server either accepts the set of queries and has downloaded data for them, or if an error has occurred.