providing dedicated scope instead of forcing transaction callback to suspend

This commit is contained in:
Adam Brown 2022-09-04 11:59:08 +01:00
parent 4e3da03062
commit d05d86a02d
2 changed files with 5 additions and 10 deletions

View File

@ -53,7 +53,6 @@ class OlmWrapper(
true -> OlmInboundGroupSession.importSession(it.sessionKey)
false -> OlmInboundGroupSession(it.sessionKey)
}
logger.crypto("import megolm ${it.sessionKey}")
olmStore.persist(it.sessionId, inBound)
}
}

View File

@ -11,9 +11,9 @@ import app.dapk.st.matrix.common.Curve25519
import app.dapk.st.matrix.common.RoomId
import app.dapk.st.matrix.common.SessionId
import com.squareup.sqldelight.TransactionWithoutReturn
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
class OlmPersistence(
private val database: DapkDb,
@ -83,13 +83,9 @@ class OlmPersistence(
}
suspend fun startTransaction(action: suspend TransactionWithoutReturn.() -> Unit) {
val transaction = suspendCoroutine {
database.cryptoQueries.transaction(false) {
it.resume(this)
}
}
dispatchers.withIoContext {
action(transaction)
val scope = CoroutineScope(dispatchers.io)
database.cryptoQueries.transaction {
scope.launch { action() }
}
}