Realm: fix realm instance close too soon

This commit is contained in:
ganfra 2022-08-05 20:33:45 +02:00
parent d0cb078f18
commit 948e24065f
2 changed files with 2 additions and 10 deletions

View File

@ -172,9 +172,6 @@ internal class RealmCryptoStore @Inject constructor(
override fun close() {
// Ensure no async request will be run later
olmAccount?.releaseAccount()
runBlocking {
realmInstance.close()
}
}
private fun updateCryptoMetadata(operation: (CryptoMetadataEntity) -> Unit) {

View File

@ -26,7 +26,6 @@ import kotlinx.coroutines.withContext
import org.matrix.android.sdk.R
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.internal.database.pagedlist.RealmTiledDataSource
import timber.log.Timber
internal fun interface RealmQueryBuilder<T : RealmObject> {
fun build(realm: TypedRealm): RealmQuery<T>
@ -60,16 +59,12 @@ internal class RealmInstance(
suspend fun open() {
coroutineScope.launch {
realm.await()
getRealm()
}.join()
}
suspend fun close() = withContext(NonCancellable) {
try {
realm.await().close()
} catch (failure: Throwable) {
Timber.e("Error whole closing realm. Instance was probably already closed.")
}
getRealm().close()
}
fun <T : RealmObject> queryResults(