asFlow

fun <T : BaseRealmObject> T.asFlow(): Flow<ObjectChange<T>>

Observe changes to a Realm object. The flow would emit an InitialObject once subscribed and then, on every change to the object an UpdatedObject. If the observed object is deleted from the Realm, the flow would emit a DeletedObject and then will complete, otherwise it will continue running until canceled.

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

Return

a flow representing changes to the object.

Throws

if called on a live RealmObject or EmbeddedRealmObject from a write transaction (Realm.write) or on a DynamicRealmObject inside a migration (AutomaticSchemaMigration.migrate).