asFlow

abstract fun asFlow(keyPaths: List<String>? = null): Flow<ResultsChange<T>>

Observe changes to the RealmResult. Once subscribed the flow will emit a InitialResults event and then a UpdatedResults on any change to the objects represented by the query backing the RealmResults. The flow will continue running indefinitely except if the results are from a backlinks property, then they will stop once the target object is deleted.

The change calculations will on on the thread represented by Configuration.SharedBuilder.notificationDispatcher.

The flow has an internal buffer of Channel.BUFFERED but if the consumer fails to consume the elements in a timely manner the coroutine scope will be cancelled with a CancellationException.

Return

a flow representing changes to the list.

a flow representing changes to the RealmResults.

Parameters

keyPaths

An optional list of model class properties that defines when a change to objects inside the RealmResults will result in a change being emitted. Nested properties can be defined using a dotted syntax, e.g. parent.child.name. Wildcards * can be be used to capture all properties at a given level, e.g. child.* or *.*. If no keypaths are provided, changes to all top-level properties and nested properties up to 4 levels down will trigger a change.

Throws

if an invalid keypath is provided.