kotlin-extensions / io.realm.kotlin / io.realm.RealmModel / isLoaded

isLoaded

fun RealmModel.isLoaded(): Boolean

Checks if the query used to find this RealmObject has completed.

Async methods like io.realm.RealmQuery.findFirstAsync return an RealmObject that represents the future result of the RealmQuery. It can be considered similar to a java.util.concurrent.Future in this regard.

Once isLoaded() returns true, the object represents the query result even if the query didn't find any object matching the query parameters. In this case the RealmObject will become a null object.

"Null" objects represents null. An exception is thrown if any accessor is called, so it is important to also check isValid before calling any methods. A common pattern is:

val person = realm.where<Person>().findFirstAsync()
person.isLoaded() // == false
person.addChangeListener { p ->
    p.isLoaded() // always true here
    if(p.isValid()) {
        // It is safe to access this person.
    }
}

Synchronous RealmObjects are by definition blocking hence this method will always return true for them. This method will return true if called on an unmanaged object (created outside of Realm).

Return
true if the query has completed, false if the query is in progress.

See Also

isValid